php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48698 strtotime and mktime
Submitted: 2009-06-26 10:47 UTC Modified: 2009-06-26 11:54 UTC
From: hlegius at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.10 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hlegius at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-26 10:47 UTC] hlegius at gmail dot com
Description:
------------
I expected the last day of given timestamp, but when mktime is the second argument of strtotime this do not happens. So, I need save mktime's result in a variable to use it later in strtotime

Reproduce code:
---------------
<?php
// FAIL !
	$timestamp = time();

	for ($i = 0; $i<10; $i++) {
		$timestamp = strtotime('yesterday', mktime(0,0,0, (date('n', $timestamp) + 1), 1, date('Y')));
		
		var_dump(date('d/m/Y', $timestamp));
	}
?>

<?php
// It's works !
	$timestamp = time();

	for ($i = 0; $i<10; $i++) {
		$timestamp = mktime(0,0,0, (date('n', $timestamp) + 1), 1, date('Y'));
		
		var_dump(date('d/m/Y', strtotime('yesterday', $timestamp))); // here, we have a $timestamp
	}
?>

Expected result:
----------------
string '30/06/2009' (length=10)
string '31/07/2009' (length=10)
string '31/08/2009' (length=10)
string '30/09/2009' (length=10)
string '31/10/2009' (length=10)
string '30/11/2009' (length=10)
string '31/12/2009' (length=10)
string '31/01/2009' (length=10)
string '28/02/2009' (length=10)
string '31/03/2009' (length=10)

Actual result:
--------------
Output of first Code:

string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)
string '30/06/2009' (length=10)


Output of second code:

string '30/06/2009' (length=10)
string '31/07/2009' (length=10)
string '31/08/2009' (length=10)
string '30/09/2009' (length=10)
string '31/10/2009' (length=10)
string '30/11/2009' (length=10)
string '31/12/2009' (length=10)
string '31/01/2009' (length=10)
string '28/02/2009' (length=10)
string '31/03/2009' (length=10)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-26 11:47 UTC] hlegius at gmail dot com
was my fault !
 [2009-06-26 11:54 UTC] scottmac@php.net
Not a bug -> Bogus
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 18 16:00:02 2025 UTC