php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14313 strtotime() and mktime() errors for dates before 1970
Submitted: 2001-12-01 23:13 UTC Modified: 2002-11-14 02:21 UTC
From: vipm at mac dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.0.6 OS: windows98
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vipm at mac dot com
New email:
PHP Version: OS:

 

 [2001-12-01 23:13 UTC] vipm at mac dot com
In PHP 4.0.6 for Linux and MacOSX, strtotime() and mktime() functions produce correct output for dates before 1970, but in Windows98 and Windows2000, I get an error (-1), e.g., strtotime("1965-3-12") 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-02 06:28 UTC] derick@php.net
Not a bug... PHP uses the native system calls for this. The windows API simply returns different (wrong) results. There is nothing that can be done about it.

Derick
 [2002-05-08 11:29 UTC] jasonh at trurocollege dot ac dot uk
This still happens in PHP 4.2.0 under WinNT (dates before 1970 are invalid).  This makes it hard to use PHP with the MSSQL extension since it converts fields to strings, and therefore you *need* to be able to convert the strings it generates (such as "Sep 1 1969 12:00AM") to timestamps if you want to perform any manipulations (or present the date in a better format).

Obviously, Windows *can* cope with dates before 1970, as can every Windows application I know of, so it's very hard to understand *why* PHP is unique in not being able to cope.  Is there not even a workaround?
 [2002-07-07 22:59 UTC] kfleming54 at hotmail dot com
I agree with jasonh@trurocollege.ac.uk.  There has to be
a fix or workaround.  If windows is returning a different
format or whatever, there should be a configuration param
or a different routine provided.  Just like javascript and
other script engines have to deal with Microsofts demand
that everyone conform to them.
 [2002-11-14 01:27 UTC] magician at romantissimo dot com
Classifying this bug as "bogus" is simply not satisfactory. The function is obviously using the wrong int size and messing up on unix times less than 1970-01-01 (Unix time zero).

This is DEFINATELY a serious and fatal bug. How can you validate a birthdate if customers are not allowed to be older that 32?
 [2002-11-14 02:21 UTC] rasmus@php.net
There are plenty of other time formats you can use for this.  See the calendar functions at php.net/calendar. 
 [2003-07-29 12:25 UTC] martinn at portant dot com
Definitely a bug.  Folks normally use strtotime() to rearrange dates input by a user into a usable date.  Ubiquitous Dreamweaver codes:
  date("Y-m-d",strtotime($theValue))
to format all user-input dates. There isn't a calendar function you can use as a work-around (as rasmus suggested).

Martin
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC