I have a date stored in a string. I want to format this date into format like "Tuesday, October 18, 2011 1:22 PM". How can I do this? I tried some of the functions like strftime / date but no luck.
You want strtotime() and date()
$time_str = '2nd November 2011';
$time = strtotime($time_str);
echo date('l, F j, Y, g:i A', $time);
//Wednesday, November 2, 2011, 12:00 AM
Thanks a lot travo! It provides the expected format, along with one warning message as below.
Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Kolkata' for '5.5/no DST' instead in
<php file name> on line 43
This just means you need to set your default timezone in one of the two ways mentioned... I usually like to do it in the php.ini file as the error shouldnt appear after you have done so.
See http://php.net/manual/en/function.date-default-timezone-set.php and http://www.php.net/manual/en/timezones.php