php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27217 strtotime returns -1 randomly
Submitted: 2004-02-11 04:30 UTC Modified: 2004-02-11 10:56 UTC
From: chkp45 at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chkp45 at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-02-11 04:30 UTC] chkp45 at hotmail dot com
Description:
------------
I read data from mssql server and get dates as "Feb 02 2004 12:00AM". I read several dates in a loop, and for some dates  strtotime returns -1 occasionally, seemingly at random. When I refresh, the wrong result changes to another date.

$d1 = strtotime($v["date"]);
printf("%s %s<br>", $v["date"], $d1); 

run 1:
Feb 02 2004 12:00AM 1075672800
Feb 03 2004 12:00AM -1
Feb 04 2004 12:00AM 1075845600
Feb 05 2004 12:00AM 1075932000
Feb 06 2004 12:00AM 1076018400
Feb 09 2004 12:00AM 1076277600
Feb 10 2004 12:00AM -1

run2:
Feb 02 2004 12:00AM -1
Feb 03 2004 12:00AM 1075759200
Feb 04 2004 12:00AM 1075845600
Feb 05 2004 12:00AM 1075932000
Feb 06 2004 12:00AM 1076018400
Feb 09 2004 12:00AM 1076277600
Feb 10 2004 12:00AM 1076364000

run3:
May 05 2003 12:00AM 1052082000
May 06 2003 12:00AM -1
May 07 2003 12:00AM 1052254800
May 08 2003 12:00AM 1052341200
May 09 2003 12:00AM 1052427600
May 12 2003 12:00AM 1052686800
May 13 2003 12:00AM 1052773200
May 14 2003 12:00AM 1052859600
May 15 2003 12:00AM 1052946000
May 16 2003 12:00AM 1053032400
May 19 2003 12:00AM 1053291600
May 20 2003 12:00AM 1053378000
May 21 2003 12:00AM 1053464400
May 21 2003 12:00AM -1
May 21 2003 12:00AM -1
May 22 2003 12:00AM 1053550800
May 23 2003 12:00AM 1053637200
May 26 2003 12:00AM 1053896400
May 27 2003 12:00AM 1053982800
May 27 2003 12:00AM 1053982800
May 27 2003 12:00AM 1053982800
May 28 2003 12:00AM 1054069200
May 28 2003 12:00AM 1054069200
May 30 2003 12:00AM 1054242000
May 30 2003 12:00AM 1054242000

This happened when I tested code in Fedora Linux 1, Apache 1.3.29 PHP 4.3.4.
Production version works ok on W2K Apache PHP 4.3.3.

On W2K date strings don't have leading zeros, eg 
"Feb 2 2004 12:00AM"



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-11 05:47 UTC] chkp45 at hotmail dot com
Further testing showed that leading zeroes in dates seems to be the problem. Using CONVERT in my sql statement showed that formats which do not have leading zeroes in dates work perfectly.
Funny, though, that May 21 2003 went wrong in run3 ???
 [2004-02-11 06:12 UTC] chkp45 at hotmail dot com
Using latest snapshot (200402111030) on linux has no effect.
 [2004-02-11 07:46 UTC] chkp45 at hotmail dot com
Sigh!

This may be still be a bug in strtotime, but in no ways critical. 

Adding trim() to date string returned by mssql solved all problems.  The length of the field shortened from 28 to 19 characters (there were spaces at the end).

No differences were found in untrimmed buffers in cases where the returned dates were identical but strtotime returned -1 for one and the correct value for the other.

Please feel free to change the status of this bug to bogus or closed, whatever your policy says.
 [2004-02-11 10:56 UTC] iliaa@php.net
not a bug. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 04:00:01 2025 UTC