|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22163 mktime returns -3662
Submitted: 2003-02-11 04:51 UTC Modified: 2003-05-18 03:08 UTC
From: andrew at strawberry-world dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.0 OS: MacOS X 10.2
Private report: No CVE-ID: None
 [2003-02-11 04:51 UTC] andrew at strawberry-world dot com

the function mktime seems to return an incorrect value for 
certain dates.



returns the value -3662

I have also tried different variations:

But all yield the same result.

If I use:

I get a UNIX timestamp back as expected.

When using the mktime() function I normally also specify 
the daylight savings time value of 0, but this also makes 
no difference, whether it is 0 or 1.

I am using PHP as built by


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-11 10:22 UTC]
I think that for some reason on your system, 03 is interpreted as 0003 and not 2003 as you intended (works fine on linux). Could you try changing the year to 2003 and see if that fixes the problem?
 [2003-02-11 14:55 UTC] andrew at strawberry-world dot com
Sorry if I misunderstand, but as my first post shows I have tried the year as 2003, as well as 03. No difference, and using the 29th as the day instead works.
 [2003-02-11 15:29 UTC]
Did you try:



 [2003-02-12 02:31 UTC] andrew at strawberry-world dot com
Yes, I have also tried (and just tried it again to make sure):


Same result, -3662

Anything else I can try to narrow down where the problem might be lying?
 [2003-02-12 05:27 UTC]
I think this must be related to daylight savings time -- 30th March 2003 is certainly the date on which DST begins in western Europe.

Can you try this, and see what you get:

echo "23:59:59 29-Mar = ", mktime(23, 59, 59, 3, 29, 2003),
     "; 00:00:01 30-Mar = ", mktime(1, 0, 1, 3, 30, 2003);

If those timestamps are 2 seconds apart, then your original mktime() is falling into the limbo of the "lost hour" due to the clocks going back (the second after 29-Mar-2003 23:59:59 must be regarded as 30-Mar-2003 01:00:00), and the algorithm used on your system returns a nonsense value when that happens.

 [2003-02-12 05:31 UTC]
Of course, I meant "; 01:00:01 30-Mar = " in the second line (although the mktime() call is correct)!
 [2003-02-12 05:53 UTC] andrew at strawberry-world dot com
ok, I used the script:

echo "$the_day<br>";
echo "23:59:59 29-Mar = ", mktime(23, 59, 59, 3, 29, 2003),    "; 01:00:01 30-Mar = ", mktime(1, 0, 1, 3, 30, 2003);


and got:

23:59:59 29-Mar = 1048982399; 01:00:01 30-Mar = -61

I thought it might be a daylight savings time problem as well, hence I thought the extra parameter I normally use would solve the problem, but it didn't. i.e.
 [2003-02-12 07:28 UTC]
H'mmm -- I get

23:59:59 29-Mar = 1048982399; 01:00:01 30-Mar = 1048982401

on my system, which is what I expected from your report.  There seems to be an extra minute or so of limbo on yours for some reason.  Can you try again with:

   mktime(1, 1, 3, 3, 30, 2003)

and let us know the result.  If it's about 1048982463, then it seems there's a whole minute in there for which you don't seem to be able to get a valid time.  If it's anything else, then something is really screwy.  Either way, it seems to be a real bug.

 [2003-02-12 07:43 UTC] andrew at strawberry-world dot com
really screwy then :-)

With the script:

echo "$the_day<br>";
echo "23:59:59 29-Mar = ", mktime(23, 59, 59, 3, 29, 2003),    "; 01:01:03 30-Mar = ", mktime(1, 1, 3, 3, 30, 2003);


I get the result:
23:59:59 29-Mar = 1048982399; 01:01:03 30-Mar = -1
 [2003-02-12 08:03 UTC]
Maybe -- or maybe my arithmetic is off!

Could you possibly do a bit more testing and report the first time after 01:01:03 that you get a likely result (and what it is!)?
 [2003-02-12 08:37 UTC] andrew at strawberry-world dot com
The first result I get is when mktime() is set to:

and the result is:

instead of -1
 [2003-02-12 09:50 UTC]
OK! That actually seems reasonable.  In Europe at least, the DST time-change is defined to take place at 01:00:00, so the hour from 01:00:00 to 01:59:59 does not exist on that date.

So it look like the bug is that the times for the hour between 00:00:00 and 00:59:59 are wrong on a date when the clock goes back for DST.

Now that we have this pinned down, I'm going to kick this to a developer who knows about the relevant bits of the PHP source to say whether this is something PHP can address, or whether it's a bug in the date/time handling of MacOS X that you'll just have to live with.
 [2003-02-12 10:08 UTC] andrew at strawberry-world dot com
Ok, yes that sounds reasonable.

I guess in the meantime instead of getting a time at midnight I should opt for another, say 11pm? I think I saw another post somewhere that recommends doing this to combat daylight savings time problems.

And I'll wait and see whether it is something that can be addressed by PHP or whether as you say it is an OS issue.
 [2003-02-12 13:12 UTC]
It's MacosX specific and not PHP bug.
And you're better off when you don't use midnight for
time anyway..

 [2003-02-13 02:48 UTC] andrew at strawberry-world dot com
Thanks for the feedback. Will continue using mktime() at a time other than midnight.
 [2003-03-30 14:55 UTC] ma499 at doc dot ic dot ac dot uk
I'm having similar problems with PHP 4.3.1 on FreeBSD 5.0-p6.

So, it is unlikely to be Mac OS X -specific (but may be xBSD specific).
 [2003-05-17 04:44 UTC] jim at babylamb dot com
I also get this bug on Mac OS X. I don't know how you can say it is bogus. OK, the time 0:0:0 on 30 Mar 03 doesn't exist. So why does it make sense to return -3662? If the input is invalid, mktime should return 0 or NULL surely? Anyway this weird behaviour should be documented.
 [2003-05-18 03:08 UTC]
I can not reproduce this on MacOSX, it works fine for me (with both 4.3.0 and 5.0.0-dev):

bash-2.05a$ sapi/cli/php ~/22163.php 
1049000400<br>23:59:59 29-Mar = 1049000399;
01:01:03 30-Mar = 1049004063bash-2.05a

$ uname -a
Darwin iMac.local. 6.6 Darwin Kernel Version 6.6: Thu May  1 21:48:54 PDT 2003; root:xnu/xnu-344.34.obj~1/RELEASE_PPC  Power Macintosh powerpc

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Feb 28 13:01:28 2020 UTC