|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12934 strftime() doesn't grok negative time_t
Submitted: 2001-08-23 17:36 UTC Modified: 2002-09-21 10:46 UTC
From: rich at horde dot org Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.3.0-dev OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rich at horde dot org
New email:
PHP Version: OS:


 [2001-08-23 17:36 UTC] rich at horde dot org

  echo strftime("%Y-%m-%d %H:%M:%S", -200000);

outputs an empty string. However, this:

  $foo = localtime(-200000000); echo $foo[5]+1900;

outputs "1963" in Linux 2.2.15, but outputs an empty string in Win2k. While negative time_t is undefined according to POSIX, time functions should probably work consistently, and strftime() should never output nothing. (That is, since there is no error condition documented for strftime(), this:

  echo strftime("HONK", -200000);

should /always/ output "HONK", even if the %-values end up empty because of the undefined meaning of negative time values.)

So, either strftime with negative time values should work,
or localtime with negative time values should fail (and the rest of the time functions made consistent with either decision). If it's decided that negative time values are to cause the functions to fail, then error conditions should probably be defined or documented for those functions (and maybe even warnings?).

(To be clear, that's not "PHP is nonconforming", but rather "undocumented and nonportable inconsistency amongst *time functions is a particularly icky form of nasal demon".)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-03 19:25 UTC]
strftime now returns false for negative values, but that doesn't solve the inconsistency. I'm really undecided if this is a Date/Time-problem or simply a lack of proper documentation.

 [2002-09-21 10:46 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 23:05:47 2022 UTC