Created
December 22, 2020 15:40
-
-
Save micoli/aa6576de84616b7672fc343604d3d12b to your computer and use it in GitHub Desktop.
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 | |
$date1 = DateTimeImmutable::createFromFormat('Y-m-d','2012-12-01'); | |
$date2 = DateTimeImmutable::createFromFormat('Y-m-d H:i:s','2012-12-10 12:00:00'); | |
dd([ | |
$date1->diff($date2)->invert, // 0 | |
$date2->diff($date1)->invert, // 1 | |
$date1->diff($date2)->format('%d'), // "8" | |
$date2->diff($date1)->format('%d'), // "8" | |
(int)$date2->diff($date1)->format('%R%a'), // -8 | |
(int)$date1->diff($date2)->format('%R%a') // 8 | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment