Reputation: 2401
I want to convert date into another format but its shows default date.
$date ='2050-12-12 00:00:00';
echo $product_expire_date = date('Ymd', strtotime($date));
It shows the default date 19700101.
Upvotes: 2
Views: 1244
Reputation: 5412
Try this:
<?php
$date = '2050-12-12 00:00:00';
$newdate = explode(" ",$date);
$newdate1 = explode("-",$newdate[0]);
echo $newdate1[0].$newdate1[1].$newdate1[2];
?>
Upvotes: -1
Reputation: 157374
First of all your date is exceeding 2038
and hence you are getting the default date... and if you simply want the date from that string, you can explode the string and echo the first index like
$date = explode(' ', '2050-12-12 00:00:00');
echo $date[0]; //Echoes date
echo $date[1]; //Echoes time
Upvotes: 2
Reputation: 27364
The valid range of a timestamp
is typically from Fri, 13 Dec 1901 20:45:54 UTC
to Tue, 19 Jan 2038 03:14:07 UTC
. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)
http://php.net/strtotime#refsect1-function.strtotime-notes
Upvotes: 3