Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug with strtotime PHP

Tags:

php

strtotime

echo date("m", strtotime("january"));

Returns 01 as expected

echo date("m", strtotime("february"));

But this returns 03

Anyone else encountered this problem?

PHP Version 5.1.6

like image 460
StefWill Avatar asked Jun 30 '11 05:06

StefWill


1 Answers

Today is the 29th. There is no 29th in February this year and because you're not specifying a day in February, it's using "today". The strtotime function uses relative dates so the 29th of February is basically the 1st March this year.

To solve your problem:

echo date("m", strtotime("February 1"));
like image 150
Francois Deschenes Avatar answered Oct 18 '22 20:10

Francois Deschenes