Last active
December 16, 2021 11:41
-
-
Save mmoreram/927287714b479b25f70fd33ee10bfc32 to your computer and use it in GitHub Desktop.
Datetime days between difference between php8.0 and php8.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Two datetimes with microseconds | |
*/ | |
$from = new DateTime('2021-12-01 11:23:38.975080'); | |
$to = new DateTime('2021-12-15 11:23:38.975066'); | |
$daysBetween = \intval((clone $to)->diff($from)->days)); | |
var_dump($daysBetween); | |
# In PHP8.0 -> 14 | |
# In PHP8.1 -> 13 | |
/** | |
* Two datetimes without microseconds | |
*/ | |
$from = new DateTime('2021-12-01 11:23:38'); | |
$to = new DateTime('2021-12-15 11:23:38'); | |
$daysBetween = \intval((clone $to)->diff($from)->days)); | |
var_dump($daysBetween); | |
# In PHP8.0 -> 14 | |
# In PHP8.1 -> 14 | |
/** | |
* Two datetimes with microseconds, but the second is 1 microsecond lower than | |
* the first one. | |
*/ | |
$from = new DateTime('2021-12-01 11:23:38.000001'); | |
$to = new DateTime('2021-12-15 11:23:38.000000'); | |
$daysBetween = \intval((clone $to)->diff($from)->days)); | |
var_dump($daysBetween); | |
# In PHP8.0 -> 14 | |
# In PHP8.1 -> 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment