Page 1 of 1
strtotime Weirdness
Posted: Sun Nov 04, 2007 12:08 am
by zardiw
Here's a real puzzler:
strtotime('10-31-2007')
Returns 12-28-2017
BUT
strtotime('10/31/2007')
or
strtotime('2007-10-31')
Works fine................It's crap like this that leads to baldness
Btw, here's a quick fix:
$WorkDate = str_replace("-", "/", $PostDate);
You guys getting DOS'd, cause it's sure slow............
z
Posted: Sun Nov 04, 2007 12:53 am
by s.dot
Really..
I get this:
Code: Select all
C:\Users\scott>php -r "$t = strtotime('10-31-2007'); echo date('n-d-Y', $t);"
12-31-1969
And nope, not geting dosd
Posted: Sun Nov 04, 2007 1:51 am
by Josh1billion
Weird... Probably a little bug or oversight, I think you should report it as a bug to the PHP team.
Posted: Sun Nov 04, 2007 1:32 am
by zardiw
Try it with /'s ..........anyway, point is moot I guess, cause that happens on v. 4.4.7, and it's going bye bye......What version did you run that on?...z
Posted: Sun Nov 04, 2007 1:54 am
by s.dot
Version 5.2.4
I wouldn't say it's a bug. The function is a bit iffy itself, trying to parse "about any english textual date description" into a timestamp.
It can't be right all the time, although seemingly month-day-year should be an easy enough time to recognize.
A more common format (for those outside of the US) is day-month-year, and it seems PHP recognizes that.
Code: Select all
C:\Users\scott>php -r "$t = strtotime('31-10-2007'); echo date('n-d-Y', $t);"
10-31-2007
So I believe in 10-31-2007 it's trying to parse it as day-month-year.
Posted: Sun Nov 04, 2007 4:07 am
by Ollie Saunders
That is strange.
You guys getting DOS'd, cause it's sure slow............
Nah we're just a bunch of cheap skates
More about the slowdown
Re: strtotime Weirdness
Posted: Sun Jan 25, 2009 10:14 am
by Popcorn
agreed scottayy,
(in PHP Version 5.2.4)
"strtotime('10-31-2007')" returned "false"
"1/2/2007" seems to be parsed as the rubbish US style
"1-2-2007" seems to be parsed as the rubbish UK style
we should all just suggest/encourage/force users use the nice unambiguous sorting-for-free ISO style "Y-m-d".