php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64148 function strtotime seems to be inaccurate
Submitted: 2013-02-05 01:29 UTC Modified: 2013-02-05 01:41 UTC
From: jeromystewart at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.21 OS: WIN SERVER 2008 VIA IIS
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: jeromystewart at gmail dot com
New email:
PHP Version: OS:

 

 [2013-02-05 01:29 UTC] jeromystewart at gmail dot com
Description:
------------
My version of PHP wasn't on the list, it is actually 5.3.8 on WIN2008 (ISS)

When calculating the unix timestamp for a given day (see Test Script) I wouldn't expect there to be a remainder at all.

The test script below demonstrates that there is a remainder ... and that remainder changes from the 13th to the 14th of March 2011.

When I ran the same script on my linux host I got the following

15045.291666667
15046.291666667
15047.291666667
15048.291666667

At least with the above, the remainder is consistent.

See below for the actual result on the windows server 2008 running IIS



Test script:
---------------
echo strtotime('2011-03-12 00:00:00')/(60*60*24);
echo '<hr>';
echo strtotime('2011-03-13 00:00:00')/(60*60*24);
echo '<hr>';
echo strtotime('2011-03-14 00:00:00')/(60*60*24);
echo '<hr>';
echo strtotime('2011-03-15 00:00:00')/(60*60*24);
echo '<hr>';



Expected result:
----------------
Expected Result: 
15045.0
<hr>
15046.0
<hr>
15047.0
<hr>
15048.0
<hr>

Actual result:
--------------
Actual Result: 
15045.333333333
<hr>
15046.333333333
<hr>
15047.291666667
<hr>
15048.291666667
<hr>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-05 01:41 UTC] rasmus@php.net
If you fed it UTC times, you would be right. But you didn't. strtotime() will use 
the current timezone and try to create the correct Unix timestamp from that. Try 
your script like this:

echo strtotime('2011-03-12 00:00:00 UTC')/(60*60*24);
 [2013-02-05 01:41 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC