Rahul Chipad
Rahul Chipad

Reputation: 2401

php strtotime giving default date

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

Answers (4)

Joke_Sense10
Joke_Sense10

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

Mr. Alien
Mr. Alien

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

Dipesh Parmar
Dipesh Parmar

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

sergio
sergio

Reputation: 5260

Use strtotime() and date():

$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));

(see strtotime and date docs on the PHP site).

Upvotes: 0

Related Questions