Created
December 15, 2022 14:51
-
-
Save relipse/723bdbb51248a68225e20ad580ccd777 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 | |
$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