Bug #71255 [Com]: Error in strtotime last day of month

From: Date: Thu, 31 Dec 2015 20:29:04 +0000
Subject: Bug #71255 [Com]: Error in strtotime last day of month
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198339@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71255&edit=1 ID: 71255 Comment by: a at b dot c dot de Reported by: ruben at solunapilates dot es Summary: Error in strtotime last day of month Status: Not a bug Type: Bug Package: Date/time related Operating System: Ubuntu 14.04 PHP Version: 5.5.30 Block user comment: N Private report: N New Comment: By that logic, date('Y', strtotime('-1 year', strtotime('2016-02-29'))) should return 2012 because 2015-02-29 doesn't exist. Previous Comments: ------------------------------------------------------------------------ [2015-12-31 19:13:19] ruben at solunapilates dot es Hi, Yes, your workaround works, but the right behaviour must be "if 31/11 doesn't exist, show a month before" because we are trying to get "a month before" (-1 month), is not? ------------------------------------------------------------------------ [2015-12-31 14:10:12] bwoebi@php.net That just happens on months with more days than previous month on the last day. December 31 - 1 month = November 31 => December 1 Better try date('F',strtotime('first day of last month')), which will give you what you expect. ------------------------------------------------------------------------ [2015-12-31 11:56:42] ruben at solunapilates dot es Description: ------------ In day 31 of December, the function date('F',strtotime('- 1 month')); returns "December" instead November. Happens all months Test script: --------------- $today=date('F',strtotime('- 1 month')); print($today); Expected result: ---------------- November Actual result: -------------- December ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71255&edit=1

« previous php.bugs (#198339) next »