|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-07-29 09:42 UTC] greenrover33 at gmail dot com
Description:
------------
strtotime goes wrong for "last day of February next year"
"last day of February next year" got the 31.03 the last day of march as result.
Test script:
---------------
$bug_from = 1406625924; // 29.07.2014 11:25
echo strftime('%d.%m.%Y %H:%M:%S', strtotime('last day of February next year', $bug_from));
echo ' != ';
echo strftime('%d.%m.%Y %H:%M:%S', strtotime('last day of February 2015', $bug_from));
die();
Expected result:
----------------
28.02.2015 00:00:00 != 28.02.2015 00:00:00
Actual result:
--------------
31.03.2015 00:00:00 != 28.02.2015 00:00:00
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 11:00:02 2025 UTC |
Workaround in PHP $string = 'last day of february next year'; $matches = array(); if (preg_match('/ of (?<month_name>january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)\s*(?<year>(([0-9]{2,4})|((last|this|next|(\-[0-9]+)|(\+[0-9]+)) years?)?))?/i', $string, $matches)) { if (empty($matches['year'])) { $string .= ' ' . date('Y'); } elseif (!is_numeric($matches['year'])) { if ($now > 0) { $string = str_replace($matches['year'], date('Y', strtotime($matches['year'], $now)), $string); } else { $string = str_replace($matches['year'], date('Y', strtotime($matches['year'])), $string); } } }