Edit report at https://bugs.php.net/bug.php?id=62784&edit=1
ID: 62784 Comment by: daniel dot rudolf at eifel-online dot com Reported by: daniel dot rudolf at eifel-online dot com Summary: DateTime: "last day of" with timestamps is buggy Status: Open Type: Bug Package: Date/time related Operating System: Windows XP PHP Version: 5.3.15 Block user comment: N Private report: N New Comment: Note that only timestamps are affected! <?php $time = new DateTime('2000-02-01 00:00:01 UTC'); $time = $time->getTimestamp(); $monthEnd = new DateTime('last day of '.date('r', $time)); echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n"; // Expected and actual result: 2000-02-01 --> 2000-02-29 ?> Previous Comments: ------------------------------------------------------------------------ [2012-08-09 07:58:46] daniel dot rudolf at eifel-online dot com Description: ------------ Using new DateTime("last day of @timestamp") doesn't work properly Test script: --------------- <?php $time = new DateTime('2012-01-01 00:00:00 UTC'); $time = $time->getTimestamp(); $monthEnd = new DateTime('last day of @'.$time); echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n"; /* ----------------------------------- */ $time = new DateTime('now'); // today = 2012-08-09 $time = $time->getTimestamp(); $monthEnd = new DateTime('last day of @'.$time); echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n"; /* ----------------------------------- */ $time = new DateTime('2020-12-12'); $time = $time->getTimestamp(); $monthEnd = new DateTime('last day of @'.$time); echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n"; /* ----------------------------------- */ $time = new DateTime('2000-02-01'); // leapyear $time = $time->getTimestamp(); $monthEnd = new DateTime('last day of @'.$time); echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n"; /* ----------------------------------- */ $time = new DateTime('2000-02-01 00:00:01 UTC'); $time = $time->getTimestamp(); $monthEnd = new DateTime('last day of @'.$time); echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n"; ?> Expected result: ---------------- 2012-01-01 --> 2012-01-31 2012-08-09 --> 2012-08-31 2020-12-12 --> 2020-12-31 2000-02-01 --> 2000-02-29 2000-02-01 --> 2000-02-29 Actual result: -------------- 2012-01-01 --> 2012-01-31 2012-08-09 --> 2012-09-08 2020-12-12 --> 2021-01-10 2000-02-01 --> 2000-03-01 2000-02-01 --> 2000-03-02 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62784&edit=1