Skip to content

Instantly share code, notes, and snippets.

@minedun6
Last active August 17, 2018 11:42
Show Gist options
  • Save minedun6/24f4d8b70f491d618e401d1ac5977f20 to your computer and use it in GitHub Desktop.
Save minedun6/24f4d8b70f491d618e401d1ac5977f20 to your computer and use it in GitHub Desktop.
Did you know you can compare DateTime objects in PHP using the spaceship operator
<?php
$dates = [
DateTime::createFromFormat('Y-m-d', '2000-02-01'),
DateTime::createFromFormat('Y-m-d', '1994-01-30'),
DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-27 12:03:33'),
DateTime::createFromFormat('Y-m-d', '2006-07-27'),
DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-27 12:04:15'),
];
usort($dates, function ($a, $b) {
return $a <=> $b;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment