in my webpage i need to calculate the day[ie. SUN,MON,TUE...] from the date .. The date is in ['06/22/2009'] this format ? How can i calculate it in to day[That is it will show me MON] in php . Please help me to find out . Thanks in advance..
$dayname = date('D', strtotime($longdate));
The date_diff() function is an inbuilt function in PHP that is used to calculate the difference between two dates. This function returns a DateInterval object on the success and returns FALSE on failure.
PHP date() Function The PHP date function is used to format a date or time into a human readable format. It can be used to display the date of article was published. record the last updated a data in a database.
Use strtotime() function to get the first day of week using PHP. This function returns the default time variable timestamp and then use date() function to convert timestamp date into understandable date. strtotime() Function: The strtotime() function returns the result in timestamp by parsing the time string.
First, you need to parse the string '06/22/2009' into a timestamp, possibly using strtotime()
:
$dt = strtotime('06/22/2009');
Then, you can format the timestamp using date()
:
$day = date("D", $dt);
If you especially want it in uppercase, use strtoupper()
:
print strtoupper($day);
For future viewers, I think this will be more helpful.
echo date('l', strtotime('11/20/2017'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With