Bug #74610 [Nab]: date function returns wrong value

From: Date: Thu, 18 May 2017 12:18:48 +0000
Subject: Bug #74610 [Nab]: date function returns wrong value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209181@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74610&edit=1 ID: 74610 Updated by: derick@php.net Reported by: shivamkss at gmail dot com Summary: date function returns wrong value Status: Not a bug Type: Bug Package: Date/time related Operating System: Mac OS Sierra PHP Version: 7.1.5 Block user comment: N Private report: N New Comment: You don't need custom logic for this at all. You can just do: <?php $a = new DateTimeImmutable("2017-05-31 09:00:00"); $b = $a->modify("first day of next month"); echo $b->format("Y-m"); Previous Comments: ------------------------------------------------------------------------ [2017-05-18 11:34:23] requinix@php.net 2017-05-31 + 1 month = 2017-06-31 and that overflows to 2017-07-01. If your application needs it to stay as the last day of the month (not overflow) then you need custom logic for that. For example, https://3v4l.org/SjYiE ------------------------------------------------------------------------ [2017-05-18 11:03:09] shivamkss at gmail dot com Description: ------------ date function is returning 2017-07 while adding 1 month to "2017-05-31 09:00:00". My time zone is Asia/Calcutta. Test script: --------------- $‌‌date = "2017-05-31 09:00:00"; return date("Y-m",strtotime("+1 month", strtotime($date))); Expected result: ---------------- It should return 2017-06 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74610&edit=1

« previous php.bugs (#209181) next »