Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Created January 8, 2023 00:28
Show Gist options
  • Save catwhocode/8f8d03ab71a7535b997013ff1dac0d56 to your computer and use it in GitHub Desktop.
Save catwhocode/8f8d03ab71a7535b997013ff1dac0d56 to your computer and use it in GitHub Desktop.
Using PHP DateTime::diff()
<?php
$datetime1 = new DateTime("2010-06-20");
$datetime2 = new DateTime("2011-06-22");
$difference = $datetime1->diff($datetime2);
echo 'Difference: '.$difference->y.' years, '
.$difference->m.' months, '
.$difference->d.' days';
print_r($difference);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment