|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-06-26 11:47 UTC] hlegius at gmail dot com
[2009-06-26 11:54 UTC] scottmac@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 19:00:01 2025 UTC |
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)