Bug #78355 [Opn->Nab]: Getting the last day of a given month failing at months of 31 days

From: Date: Wed, 31 Jul 2019 02:21:52 +0000
Subject: Bug #78355 [Opn->Nab]: Getting the last day of a given month failing at months of 31 days
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222022@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78355&edit=1 ID: 78355 Updated by: requinix@php.net Reported by: belbayar at mobicom dot mn Summary: Getting the last day of a given month failing at months of 31 days -Status: Open +Status: Not a bug Type: Bug Package: Date/time related Operating System: Centos 7 PHP Version: 7.3Git-2019-07-31 (Git) Block user comment: N Private report: N New Comment: Your Expected and Actual are backwards. 2019-07-31 - 1 month = 2019-06-31 which overflows to 2019-07-01. strtotime() supports a lot of expressions. One of them fits your needs exactly. https://www.php.net/manual/en/datetime.formats.relative.php Previous Comments: ------------------------------------------------------------------------ [2019-07-31 02:11:15] belbayar at mobicom dot mn Description: ------------ I have a problem like this. For a given date I need to get the last day of the previous month. For example today is 2019-07-31, I needed date is 2019-06-30 Test script: --------------- echo date('Y-m-t', strtotime("2019-07-31" . '-1 months')); echo date("Y-m-d", strtotime("-1 Month")); Expected result: ---------------- 2019-07-31 2019-07-01 Actual result: -------------- 2019-06-30 2019-06-01 or 2019-06-30 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78355&edit=1

« previous php.bugs (#222022) next »