php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35043 mktime() seems to return odd results for 31st of October
Submitted: 2005-11-01 10:58 UTC Modified: 2005-11-01 11:14 UTC
From: daniel at septum dot org Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 6CVS-2005-11-01 (snap) OS: Linux 2.4
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: daniel at septum dot org
New email:
PHP Version: OS:

 

 [2005-11-01 10:58 UTC] daniel at septum dot org
Description:
------------
When involving the 31st of October (either by finding out number of days between 2005-10-29 and 2005-10-31 or 2005-10-31 and 2005-11-01), it gives the wrong result.

Days between 2005-10-29 and 2005-10-30 returns 1 (which is correct), however, days between 2005-10-29 and 2005-10-31 returns 3 (which is incorrect, it should be 2).

It seems to work fine for 2001, 2002, 2003 and 2006-2009, not for 2004 and 2005 (as stated above).

Reproduce code:
---------------
$dos = "2005-10-30"; 

$year = substr($dos, 0, 4);   
$month = substr($dos, 5, 2);   
$day = substr($dos, 8, 2);   

$mktime_dos = mktime(0, 0, 0, $month, $day, $year);   

$next_month = "2005-11-01"; 

$year = substr($next_month, 0, 4);   
$month = substr($next_month, 5, 2);   
$day = substr($next_month, 8, 2); 

$mktime_now = mktime(0, 0, 0, $month, $day, $year);   

$difference = $mktime_now - $mktime_dos; 
$signed_up_days_ago = ceil($difference / 60 / 60 / 24); 

echo $signed_up_days_ago . "\n";


Expected result:
----------------
2

Actual result:
--------------
3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-01 11:14 UTC] derick@php.net
We are happy to tell you that you just discovered Daylight Savings
Time. For more information see:
http://webexhibits.org/daylightsaving/b.html
Instead of using mktime/date consider using gmmktime and gmdate which do
not suffer from DST.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 08:01:30 2024 UTC