php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44536 wrong result (timestamp)
Submitted: 2008-03-26 11:28 UTC Modified: 2008-03-26 12:01 UTC
From: anas1305 at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2CVS-2008-03-26 OS: XP and 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: anas1305 at gmail dot com
New email:
PHP Version: OS:

 

 [2008-03-26 11:28 UTC] anas1305 at gmail dot com
Description:
------------
function return wrong result between 2 dates 2008-03-30 -> 2008-03-31.
PHP version : 5.2.3

Reproduce code:
---------------
$ddebut = "2008-03-30";
$dfin   = "2008-03-31";
	
$tab_ddebut = explode("-", $ddebut);
$tab_dfin   = explode("-", $dfin);

$timestamp_ddebut = mktime(0, 0, 0, $tab_ddebut[1], $tab_ddebut[2], $tab_ddebut[0]);
$timestamp_dfin	  = mktime(0, 0, 0, $tab_dfin[1], $tab_dfin[2], $tab_dfin[0]);

echo abs(($timestamp_dfin - $timestamp_ddebut)/86400);


Expected result:
----------------
this code abs(($timestamp_dfin - $timestamp_ddebut)/86400) return wrong result : 0.958333333333. the correct result is 1.

Actual result:
--------------
0.958333333333

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-26 12:01 UTC] jani@php.net
Congratulations! You have found the DST (daylight saving time) and it's problems. :) Hint: Use gmmktime() instead and you'll never encounter this in the future.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jun 02 23:01:26 2025 UTC