Bug #80748 [Opn->Fbk]: DateInterval wrongly counts DateTime->diff days

From: Date: Sat, 13 Feb 2021 20:49:52 +0000
Subject: Bug #80748 [Opn->Fbk]: DateInterval wrongly counts DateTime->diff days
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232138@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80748&edit=1 ID: 80748 Updated by: requinix@php.net Reported by: palansher at outlook dot com Summary: DateInterval wrongly counts DateTime->diff days -Status: Open +Status: Feedback Type: Bug Package: Date/time related Operating System: ubuntu 18.04 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Google thinks the answer is 44202, and that's what I get on 3v4l for both $afterDates. https://3v4l.org/QkOl8 Are you sure the timezone doesn't matter? Is your timezone database up to date? Previous Comments: ------------------------------------------------------------------------ [2021-02-13 20:45:25] palansher at outlook dot com Description: ------------ DateTime->diff returns different days, depending on how many seconds passed from midnight on a target date. This behaviour is independent of timezone settings. Tested on PHP 7.2-7.4 The bug doesn't appear if you use short period: <?php $beforDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-01 00:00:00'); $afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-08 00:00:43'); $dtInterval = $beforDate->diff($afterDate); $daysPassed = $dtInterval->days; echo "days passed if target date have 42 seconds from midnight: $daysPassed" . PHP_EOL; $afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-08 00:00:43'); $dtInterval = $beforDate->diff($afterDate); $daysPassed = $dtInterval->days; echo "days passed if target date have 43 seconds from midnight: $daysPassed" . PHP_EOL; Test script: --------------- <?php $beforDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-01 00:00:00'); $afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '2021-01-08 00:00:42'); $dtInterval = $beforDate->diff($afterDate); $daysPassed = $dtInterval->days; echo "days passed if target date have 42 seconds from midnight: $daysPassed" . PHP_EOL; $afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '2021-01-08 00:00:43'); $dtInterval = $beforDate->diff($afterDate); $daysPassed = $dtInterval->days; echo "days passed if target date have 43 seconds from midnight: $daysPassed" . PHP_EOL; Expected result: ---------------- days passed: 44201 Actual result: -------------- days passed: 44202 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80748&edit=1

« previous php.bugs (#232138) next »