Skip to content

Instantly share code, notes, and snippets.

@relipse
Created December 15, 2022 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relipse/723bdbb51248a68225e20ad580ccd777 to your computer and use it in GitHub Desktop.
Save relipse/723bdbb51248a68225e20ad580ccd777 to your computer and use it in GitHub Desktop.
<?php
$date = $argv[1] ?? null;
$curdate = $argv[2] ?? 'now';
if (empty($date)){
die('Date: '.$date.' is invalid. Use first argument for date of birth and second argument for date to calculate from like:'.
"\nphp birthday.php \"Nov 1, 1984\" \"Mar 1, 2004\""."\n");
}
try{
$dt = new \DateTime($date);
$curdt = new \DateTime($curdate);
$age = $dt->diff($curdt)->y;
echo $age."\n";
}catch(\Throwable $e){
die($e->getMessage()."\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment