php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10694 mktime leap year bug
Submitted: 2001-05-07 01:50 UTC Modified: 2001-08-31 14:48 UTC
From: schnitten at gmx dot at Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 4.0.4 OS: Redhat 6.2
Private report: No CVE-ID: None
 [2001-05-07 01:50 UTC] schnitten at gmx dot at
first of all:
I use php 4.0.1pl2 and don't have the possibility to upgrade. Please verify with latest version. 

I tried to add 12 months to a given timestamp and figured out that mktime() doesn't include a 29th February into its calculations. Effect is, that following code doesn't jump forward 1 year during each loop. Every leap year 1 day gets lost!

$a = mktime(0,0,0,1,1,1970);		
for ($i=0; $i<20; $i++) {
	$a = mktime(0,0,3600 +$a,1+12,1,1970);
	$b = date("d-m-Y", $a);
	print "Date: $b<br>";
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-07 04:23 UTC] derick@php.net
Assigning to myself
 [2001-08-31 12:06 UTC] sander@php.net
Status after almost three months???
 [2001-08-31 14:05 UTC] schnitten at gmx dot at
The problem is how you look at it:
mktime first calculates year + month...
the last step is to add the seconds.

I wanted this the other way round. Would be a nice feature to select the priority of the different input values. When you use unix timestamps for calculations its very difficult to add 1 year (or something similar) to that date...
 [2001-08-31 14:48 UTC] derick@php.net
Ok, I was just trying to explain the same thing after some
investigating...

Derick
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat May 21 22:03:33 2022 UTC