Tuesday, 1 February 2011

Strange behavior of strtotime() function

Some of the PHP functions for date manipulation make me surprised. Working on the recent project I faced the problem using function strtotime(). I needed get the list of months one by one from current date.

Seems, everything is simple, I solved this calling the function date("m", strtotime("+ n month")) in loop and got the the list of months I needed. But all the interesting things started from the date 31th of January. I got the list of months with two Marchs.

First I was a loss but then started looking through the documentation for this function and read the comments described this strange behavior of this function.

Not evident behavior leads to big bugs. Be careful working with this function.

No comments:

Post a Comment