Edit report at https://bugs.php.net/bug.php?id=60257&edit=1

 ID:                 60257
 Comment by:         it at ezy2c dot com
 Reported by:        it at ezy2c dot com
 Summary:            ZERO DATES IN STRTOTIME
 Status:             Duplicate
 Type:               Bug
 Package:            Date/time related
 Operating System:   CENTOS 5 64 bit
 PHP Version:        5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

Wow, OK. The Spell check went horrible. :)

However the logic of strtotime SHOULD BE:

Strtotime -> IF Running on 64-Bit AND input is 0000-00-00 00:00:00 then return 
NULL.

Its fine if the date is in the past, just NOT when its 0000-00-00 00:00:00 (the 
default for date column value in MANY databases).

This creates inconsistency in the PHP language across platforms is what im 
trying to say. It may not be a BUG but it makes PHP less of a reliable language 
due to the unexpected behaviour, and I'd like to see you SERIOUSLY consider 
fixing this.


Previous Comments:
------------------------------------------------------------------------
[2011-11-13 21:44:42] it at ezy2c dot com

Perhaps there should be an option to return NULL. This isnt great when your 
dealing with MySQL databases that have date fields with 0000-00-00 00:00:00 
format. At least when it returns null the date field interprets it as the 1970 
date. This is an expedted date wince 1970 is the start of unix epoch.

This Created variability over 32-bit and 64-bit systems and hence would need to 
adjust the code base to do something kind of work around (however some systems 
use lots of date values and this is VERY difficult to replace all the strtotime 
references) see below for a wrapper function. I feel that this logic SHOULD 
exist in 64 bit ONLY if the date is 0000-00-00 00:00:00, this way database 
default values can be handles easier and is cross compatible in both 64 or 32 
bit systems. 

YOUR view maybe that is isnt a BUG, however its more of Incompatibility and 
Inconsistency across platforms and 32/64 bit systems. I would VERY much like 
you to consider changing this.

function str2time($time)
{
        if(strtotime($time)=="-62170020000")
        {
                return NULL;
        }
        else
        {
                return strtotime($time);
        }
}

------------------------------------------------------------------------
[2011-11-11 12:25:09] ahar...@php.net

Not a bug: on 64 bit platforms, 0000-00-00 00:00:00 is within range, so 
strtotime() returns a UNIX timestamp corresponding to that date. On 32 bit 
platforms, it's out of range, so strtotime() returns NULL to signal the error.

Duplicate of bug #53662 (among others).

------------------------------------------------------------------------
[2011-11-11 03:31:33] it at ezy2c dot com

When I strtotime("0000-00-00 00:00:00") in the Linux Box I get -62170020000, 
when I do it on the windows box it returns NULL. Maybe this is the root of the 
issue, at least when it returns NULL it converts to 1970-01-01 10:00:00

------------------------------------------------------------------------
[2011-11-11 03:08:56] it at ezy2c dot com

After a search of the web I have uncovered that other users experience this in 
lots of 5+ versions of PHP on 64-bit *unix OS's. 

If its a 64 bit OS, strtotime should detect if its a ZERO date value (as mysql 
uses as default value etc) ie. 0000-00-00 00:00:00 and return the 1970 value as 
my Windows machine does.

By the way my Windows Machine is a 64-Bit Windows 7 machine with XAMPP, and it 
returns a 1970 date. Please Fix this as we have a LOT of code that relies on 
strtotime's ability.

------------------------------------------------------------------------
[2011-11-10 23:40:19] it at ezy2c dot com

Description:
------------
Hi I have noticed that when i use zero date in windows it converts to the 
expected 1970 date however on our Centos 5 Server it fails.

See live script http://amo2.flsecure.com/testdate.php

Test script:
---------------
EXAMPLE CODE:
$zerodate="0000-00-00 00:00:00";
$convertdate=date("Y-m-d H:i:s",strtotime(0000-00-00 00:00:00));
echo("ORIG: ".$zerodate." | CONVERTED: ".$convertdate.");

RESULT:
ORIG: 0000-00-00 00:00:00 | CONVERTED: -0001-11-30 00:00:00

On MY WINDOWS BOX:
ORIG: 0000-00-00 00:00:00 | CONVERTED: 1970-01-01 10:00:00



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60257&edit=1

Reply via email to