php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16594 mktime() when passed a 0 for the day of the month to get the last day is broken
Submitted: 2002-04-14 02:34 UTC Modified: 2002-04-14 08:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: lchang at cc dot gatech dot edu Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.1.2 OS: FreeBSD 4.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 1 = ?
Subscribe to this entry?

 
 [2002-04-14 02:34 UTC] lchang at cc dot gatech dot edu
When you use mktime(0,0,0,<month>,<day>,<year>) and specify 0 as the day to get the last day of the month, the last day of the month returned is off. It seems that the months are all off by 1 after January. So with mktime(), for February, the last day is the 31st, for March it is the 28th, for April it is the 31st, etc. And instead February should be the 28th, March the 31st, and April the 30th, etc...

<?php
  //Last day should be 28, but is 31
  $day = getdate( mktime(0,0,0,2,0,2002) );
  print 'The last day for February is: ' . $day[mday]
        .'<br>';
  //Last day should be 31, but is 28
  $day = getdate( mktime(0,0,0,3,0,2002) );
  print 'The last day for March is: ' . $day[mday];
  
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-14 08:34 UTC] hholzgra@php.net
intended behaviour

day zero is the day before the first day of
the given month, so it is obviously the last
day of the month *before* the given one
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 21:01:30 2024 UTC