date - PHP strtotime behaviour -


the following lines of code returns 2 different outputs on 2 different servers , b:

echo date("m y", strtotime("2015-01")); echo date("m y", strtotime("2015-02")); 

the expected output "jan 2015" , "feb 2015" correct on server a.

but same code on server b returns output "jan 2015" , "mar 2015".

on debugging, found strtotime function on server b returning timestamp current day of every month (today 29th), explains why "2015-02" shown "march 2015" (since there no feb 29, 2015). yesterday, code returning same output on both servers since feb 28th valid , translated feb 2015.

so essentially, on server a, effective code is

 echo date("m y", strtotime("2015-01-01"));  echo date("m y", strtotime("2015-02-01")); 

while on server b, effective code

echo date("m y", strtotime("2015-01-29")); //or, strtotime("2015-01-[current day]") echo date("m y", strtotime("2015-02-29")); 

why there difference between these 2 servers?

this problem different version of php. there bc in php 5.2.7, documentation:

in php 5 prior 5.2.7, requesting given occurrence of given weekday in month weekday first day of month incorrectly add 1 week returned timestamp. has been corrected in 5.2.7 , later versions.

demo

server has php > 5.2.7, server b has php < 5.2.7.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -