Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date to day conversion in php

Tags:

php

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..

like image 893
Sakthivel Avatar asked Jun 30 '09 07:06

Sakthivel


People also ask

How get the day name from a date in PHP?

$dayname = date('D', strtotime($longdate));

How can I calculate days between dates in PHP?

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.

What does Date () do in PHP?

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.

How do you get the day of the week from a date in PHP?

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.


2 Answers

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);
like image 177
harto Avatar answered Oct 19 '22 04:10

harto


For future viewers, I think this will be more helpful.

echo date('l', strtotime('11/20/2017'));
like image 34
Mahfuzur Rahman Avatar answered Oct 19 '22 05:10

Mahfuzur Rahman