stevesimo Posted April 18, 2007 Share Posted April 18, 2007 Hi, I am trying to validate whether or not a date of birth entered in dd/mm/yyyy format is between 16 and 69 years old. Suppose we have todaysdate = 18/04/2007 The minimum allowed date of birth would be 18/04/1991 and the maximum allowed date of birth would be 18/04/1938. I have looked at using strtotime but this only does dates from 1970 (I think) Can anyone help me with this as I am really stuck and not sure how to compare the dates. Thanks Steve (Blackpool) Link to comment https://forums.phpfreaks.com/topic/47542-solved-calculate-age-based-on-date-of-birth/ Share on other sites More sharing options...
Orio Posted April 18, 2007 Share Posted April 18, 2007 <?php list($d, $m, $y) = explode("/", $date); $time = mktime(0, 0, 0, $m, $d, $y); $age = floor((now() - $time) / 31557600); //This number is the number of secs in a year if($age < 69 && $age > 16) echo "Good age!"; else echo "Bad age!"; ?> Orio. Link to comment https://forums.phpfreaks.com/topic/47542-solved-calculate-age-based-on-date-of-birth/#findComment-232047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.