Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php date function is returning wrong year

Tags:

date

php

I can't figure this out for the life of me. I have a date that needs to be formatted. There are multiple dates on the page that format just fine.

echo date('M jS o',strtotime('2012-12-31')) //is returning "Dec 31st 2013". 
echo date('M jS o',strtotime('2013-12-31')) //is returning "Dec 31st 2014".

and so on, going forward the year is always one year off.

but

date('M jS o',strtotime('2011-12-31')) //returns correctly "Dec 31st 2011". 
date('M jS o',strtotime('2010-12-31')) //returns correctly "Dec 31st 2010".

and so on, going backward they are fine. Is this some apocalyptic scheme the Mayans threw at us or something? :)

Any ideas? I assume there is a simple answer.

Thanks!!

like image 210
leviathenator Avatar asked Sep 24 '26 07:09

leviathenator


1 Answers

Use Y for year, not o. Per the date docs:

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)

like image 93
ceejayoz Avatar answered Sep 26 '26 02:09

ceejayoz