php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64489 wrong caclulation with date_diff
Submitted: 2013-03-22 12:00 UTC Modified: 2017-01-13 16:01 UTC
Votes:2
Avg. Score:2.5 ± 1.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: phpbug at samic dot us Assigned: heiglandreas (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4Git-2013-03-22 (snap) OS: Linux Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at samic dot us
New email:
PHP Version: OS:

 

 [2013-03-22 12:00 UTC] phpbug at samic dot us
Description:
------------
date_diff has a problem with a specific date
it doesn't calculate days between two dates correctly
please see the example
( it seems there is a similar problems: http://www.php.net/manual/en/datetime.diff.php#101990 )

Test script:
---------------
$interval = date_diff(date_create('2000-03-21'), date_create('2013-03-21'));
echo $interval->format('%a') . "<br>\n";  // will output 4747


$interval = date_diff(date_create('2000-03-21'), date_create('2013-03-22'));
echo $interval->format('%a') . "<br>\n";  // will output 4749   --- WRONG!


$interval = date_diff(date_create('2000-03-21'), date_create('2013-03-23'));
echo $interval->format('%a') . "<br>\n";  // will output 4749


$interval = date_diff(date_create('2000-03-21'), date_create('2013-03-24'));
echo $interval->format('%a') . "<br>\n";  // will output 4750

Expected result:
----------------
4747
4748
4749
4750


Actual result:
--------------
4747
4749
4749
4750



the second calculation is wrong

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-22 15:58 UTC] aharvey@php.net
Which time zone is your PHP installation using — ie what do you get if you echo 
date_default_timezone_get()?
 [2013-03-22 15:58 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2013-03-22 17:53 UTC] phpbug at samic dot us
My default timezone is set to "Asia/Tehran"
as I'm here ;)
 [2013-03-22 18:01 UTC] phpbug at samic dot us
Mr. Schindhelm who had found the similar problem (http://www.php.net/manual/en/datetime.diff.php#101990) emailed me and said the problem has got fixed. I'm sorry I didn't check his problem too and just thought it's similar to my problem.
 [2013-03-22 18:01 UTC] phpbug at samic dot us
-Status: Feedback +Status: Open
 [2017-01-13 16:01 UTC] heiglandreas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: heiglandreas
 [2017-01-13 16:01 UTC] heiglandreas@php.net
This has been fixed by now. Calculation seems to be consistend by now. Tested on PHP 7.1
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 11:01:36 2025 UTC