Reputation: 35
I have the following string:
$date = 2011-08-29 14:53:15;
when I do this:
echo date('F j, Y', $date);
I get December 31, 1969 instead of August 29, 2011. How to get the right date?
Upvotes: 1
Views: 122
Reputation: 4701
<?php
$date = strtotime($date);
echo date('F j, Y', $date);
?>
To explain...
The function date()
is expecting a unix time-stamp (something like 23498034). the function strtotime()
takes a normal looking date that a person would make, and converts it to a timestamp. Then you're good to go.
Upvotes: 2