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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 10:01:30 2025 UTC