php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54005 mktime() changes days when it should't
Submitted: 2011-02-13 15:47 UTC Modified: 2011-02-15 22:35 UTC
From: taxi at a-city dot de Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Linux (Debian)
Private report: No CVE-ID: None
 [2011-02-13 15:47 UTC] taxi at a-city dot de
Description:
------------
Hi,
I'm trying to use mktime() to calculate when one month is over.

As you can see the day changed at february (which wa fixed by a quick&dirty-really-bad-hack) and May (more untested).

I think the problem with february is that mktime() doesn't know that february only has 28 days?

Test script:
---------------
<?
$now = time();
$a = mktime(1, 0, $now, 1, 1, 1970);
$b = mktime(1, 0, $now, 1 + 1, 1, 1970);
$c = mktime(1, 0, $now, 1, 1 + 28, 1970); //28 days couse this month has only $
$d = mktime(1, 0, $now, 1 + 1, 1 + 28, 1970);
$e = mktime(1, 0, $now, 1 + 2, 1 + 28, 1970);
$f = mktime(1, 0, $now, 1 + 3, 1 + 28, 1970);
$g = mktime(1, 0, $now, 1 + 4, 1 + 28, 1970);
$h = mktime(1, 0, $now, 1 + 5, 1 + 28, 1970);
echo "Now: $now (".date("d.m.Y",$now).")<br>
a: $a (".date("d.m.Y",$a).")<br>
b: $b (".date("d.m.Y",$b).")<br>
c: $c (".date("d.m.Y",$c).")<br>
d: $d (".date("d.m.Y",$d).")<br>
e: $e (".date("d.m.Y",$e).")<br>
f: $f (".date("d.m.Y",$f).")<br>
g: $g (".date("d.m.Y",$g).")<br>
h: $h (".date("d.m.Y",$h).")";
?>

Expected result:
----------------
Now: 1297608181 (13.02.2011)
a: 1297608181 (13.02.2011)
b: 1300286581 (13.03.2011)
c: 1300027381 (10.03.2011)
d: 1302702181 (13.04.2011)
e: 1305121381 (13.05.2011)
f: 1307799781 (13.06.2011)
g: 1310391781 (13.07.2011)
h: 1313070181 (13.08.2011)


Actual result:
--------------
Now: 1297608181 (13.02.2011)
a: 1297608181 (13.02.2011)
b: 1300286581 (16.03.2011)
c: 1300027381 (13.03.2011)
d: 1302702181 (13.04.2011)
e: 1305121381 (11.05.2011)
f: 1307799781 (11.06.2011)
g: 1310391781 (11.07.2011)
h: 1313070181 (11.08.2011)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-15 22:35 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-02-15 22:35 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

I've no idea what you're doing with the 3rd argument to mktime(). You're passing in Unix timestamps, but with an hour of 1? There is going to be some DST issues with this at least. Please don't abuse functions like this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 03:01:30 2024 UTC