|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48458 mktime produces huge negative numbers
Submitted: 2009-06-03 10:52 UTC Modified: 2009-06-03 11:11 UTC
From: post at oliver-schieche dot de Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.9 OS: Debian 4 2.6.18-6-amd64
Private report: No CVE-ID: None
 [2009-06-03 10:52 UTC] post at oliver-schieche dot de
Trying to get mktime to create a timestamp for today at 00:00 hours, odd results are returned. Previous versions of PHP 5 returned a correct timestamp even without adding 1900 to the year.

This change to mktime behavior was not documented in the ChangeLog.

Reproduce code:
$v = localtime(time(), TRUE);
$tm1 = mktime(0, 0, 0, $v['tm_mon']+1, $v['tm_mday'], $v['tm_year']);
$tm2 = mktime(0, 0, 0);

Expected result:
tm1 == tm2 == 1243980000  // 2009-06-03 00:00:00

Actual result:
tm1 = -58714246800
tm2 = 1243980000


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-03 10:56 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

$v['tm_year'] contains the years since 1900. 
 [2009-06-03 11:08 UTC] post at oliver-schieche dot de
I know that years returned from localtime() start with 1900. But the problem with mktime still remains.

for PHP 5.2.6
returns 1243980000

and the large negative number will be returned for the exact same call to mktime() in PHP 5.2.9
 [2009-06-03 11:11 UTC]
The year 109 is a long time in the past. As seconds are counted from 1970, getting a negative number happens for any year < 1970.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 02:01:28 2024 UTC