maxlibin Posted May 2, 2013 Share Posted May 2, 2013 i have a string like this "20 Dec, 2011", is there a way find out which day of the week is this? Link to comment https://forums.phpfreaks.com/topic/277532-php-find-out-day-of-the-week-from-string/ Share on other sites More sharing options...
Psycho Posted May 2, 2013 Share Posted May 2, 2013 Yes. What day of week value are you wanting? Mon - Sun or 1 - 7? You would want to use date() along with strtotime(). After testing it looks like strtotime() can't use that string format as it is. You'll need to remove the comma. $date_string = "20 Dec 2013"; //Convert to timestamp $date_timestamp = strtotime(str_replace(',', '', $date_string)); //Output day of week string echo date('D', $date_timestamp); //Output: Friday //Output day of week number echo date('N', $date_timestamp); //Output: 5 Link to comment https://forums.phpfreaks.com/topic/277532-php-find-out-day-of-the-week-from-string/#findComment-1427706 Share on other sites More sharing options...
DaveyK Posted May 2, 2013 Share Posted May 2, 2013 var_dump(date('l', strtotime('20 Dec, 2011'))); // "Friday" Or, what Psycho said. Link to comment https://forums.phpfreaks.com/topic/277532-php-find-out-day-of-the-week-from-string/#findComment-1427707 Share on other sites More sharing options...
maxlibin Posted May 2, 2013 Author Share Posted May 2, 2013 thanks guy, appreciated. Link to comment https://forums.phpfreaks.com/topic/277532-php-find-out-day-of-the-week-from-string/#findComment-1427709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.