php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6781 Error in mktime() funtion (Serious???)
Submitted: 2000-09-16 23:41 UTC Modified: 2000-09-17 04:33 UTC
From: landen at frg dot eur dot nl Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.0.1pl2 OS: Linux RH 6.0, 6.1, 6.2
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: landen at frg dot eur dot nl
New email:
PHP Version: OS:

 

 [2000-09-16 23:41 UTC] landen at frg dot eur dot nl
I was using the mktime function to calculate the number of days between two dates by dividing the difference by 86400 (the number of seconds in a day) when I stumbled across this one (my code came up with fractional results):

  echo "2001/03/25: has ",mktime(0,0,0,3,26,2001) - mktime(0,0,0,3,25,2001)," seconds<br>";
  echo "2001/03/26: has ",mktime(0,0,0,3,27,2001) - mktime(0,0,0,3,26,2001)," seconds<br>";

It seems PHP thinks the number of seconds in 2001/3/25 is 82800!!! 

I'm not sure if this could be a bug in a library, but it even occurs on an ancient Slackware installation. I tried the same in Perl using the POSIX module which comes up with the right answer.

Now, to confuse me even more MySQL seems to have the same bug, try this:

  select unix_timestamp("2001/3/26") - unix_timestamp("2001/3/25");

Is it possible that you copied this bug from the MySQL code?

Anyway, this could start causing big problems in date related software next year (or maybe nobody would notice)...

My configure line (I don't see how php.ini could be relevant):

./configure --with-apxs=/usr/sbin/apxs --with-xml --with-pdflib --with-zlib --with-mysql=/usr --with-oracle --with-ldap

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-17 00:56 UTC] landen at frg dot eur dot nl
It seems there are dates that have more and dates that have less seconds, try this quick and dirty code (I pretended all months have 31 days):

  echo "<pre>";
  for ($year=2000; $year < 2005; $year++) {
    for ($month=1; $month <= 12; $month++) {
      for ($day=1; $day <=31; $day++) {
        $diff=mktime(0,0,0,$month,$day+1,$year) - mktime(0,0,0,$month,$day,$year);
        if ($diff != 86400) echo "$year/$month/$day has $diff seconds\n";
      } 
    } 
  } 

Results:

2000/3/26 has 82800 seconds
2000/10/29 has 90000 seconds
2001/3/25 has 82800 seconds
2001/10/28 has 90000 seconds
2002/3/31 has 82800 seconds
2002/10/27 has 90000 seconds
2003/3/30 has 82800 seconds
2003/10/26 has 90000 seconds
2004/3/28 has 82800 seconds
2004/10/31 has 90000 seconds

 [2000-09-17 01:52 UTC] landen at frg dot eur dot nl
OK, I found out that it was just Daylight Savings Time!

I wish I could just delete this message so my stupidity won't be displayed so publicly ;)



 [2000-09-17 04:33 UTC] derick@php.net
You just discovered daylight savings time.... closing
 [2002-04-17 14:39 UTC] s_esat at hotmail dot com
I'm glad this hasn't been deleted!
It's helped solved a problem due to DST.

Thanks :)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC