Poonam Ghangas
Poonam Ghangas

Reputation: 41

yyyy-mm-dd format with strtotime returning wrong result

$originalDate1 = '2013-12-30';

echo $newDate = date("o-m-d", strtotime($originalDate1));

Displaying 2014 instead of 2013

Upvotes: 0

Views: 4843

Answers (2)

Satish Sharma
Satish Sharma

Reputation: 9635

use Y-m-d instead of o-m-d

$originalDate1 = '2013-12-30';

echo $newDate = date("Y-m-d", strtotime($originalDate1)); // will output 2014-12-30

Upvotes: 1

Alexander Nenkov
Alexander Nenkov

Reputation: 2910

The problem is the "o"

ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)

You should use "Y" instead.

Upvotes: 2

Related Questions