Edit report at https://bugs.php.net/bug.php?id=65412&edit=1
ID: 65412 Comment by: mail+php at requinix dot net Reported by: laurisnet at inbox dot lv Summary: strtotime('2013-07-31 -1 month') return wrong result Status: Not a bug Type: Bug Package: Date/time related Operating System: Windows 7 64bit PHP Version: 5.4Git-2013-08-07 (Git) Block user comment: N Private report: N New Comment: "-1 month" is literally subtracting one month from the date. 2013-07-31 becomes 2013-06-31 which overflows to 2013-07-01. Likewise "2013-03-31 -1 month" becomes 2013-03-03. If you want the last day of the previous month then the method I know (using only strtotime) is going to the beginning of the month, subtracting a month, and going to the last day: strtotime("2013-07-31, first day of, -1 month, last day of") Keep an eye on http://php.net/datetime.formats.relative But it's much easier with mktime(0, 0, 0, month, 0, year). Previous Comments: ------------------------------------------------------------------------ [2013-08-07 20:09:36] ras...@php.net This is not a bug. This is standard behaviour for date arithmetic when the target date is impossible. There is an explanation from the GNU tools here: http://www.gnu.org/software/tar/manual/html_chapter/Date-input- formats.html#SEC125 ------------------------------------------------------------------------ [2013-08-07 09:19:10] laurisnet at inbox dot lv Description: ------------ Function strtotime() return wrong value for 2013-07-31 date with parameters: A) -1 month B) last month Test script: --------------- <? // This returns: 2013-07-01 // But expected was: 2013-06-30 echo date("Y-m-d", strtotime('2013-07-31 -1 month')); ?> Expected result: ---------------- 2013-06-30 Actual result: -------------- 2013-07-01 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65412&edit=1