Skip to content

Instantly share code, notes, and snippets.

@micoli
Created December 22, 2020 15:40
Show Gist options
  • Save micoli/aa6576de84616b7672fc343604d3d12b to your computer and use it in GitHub Desktop.
Save micoli/aa6576de84616b7672fc343604d3d12b to your computer and use it in GitHub Desktop.
<?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