Given the following timestring:
$str = '2000-11-29';
$php_date = getdate( $str );
echo '<pre>';
print_r ($php_date);
echo '</pre>';
How to get the year/month/day in PHP?
[seconds] => 20
[minutes] => 33
[hours] => 18
[mday] => 31
[wday] => 3
[mon] => 12
[year] => 1969
[yday] => 364
[weekday] => Wednesday
[month] => December
[0] => 2000
I don’t know why I get 1969 for year.
Thank you
You can use
strtotimeto parse a time string, and pass the resulting timestamp togetdate(or usedateto format your time).Note that
strtotimewill returnfalseif the time string is invalid or can’t be parsed. When the timestamp you’re trying to parse is invalid, you end up with the 1969-12-31 date you encountered before.