I’m real bad at using the PHP date and time functions. I was hoping someone could tell me how I could check to see if someone is 18 by passing in a date of birth to a function and obviously comparing it to today’s date.
@DexterMorganJan 02.2011 — #Is this what you mean? [code=php] <?php /** * Check if a given D.O.B is over 18 * @param string date of birth * @return bool */ function checkAge($dob){ $age = strtotime($dob); $eighteen = 566092800; // 18 years
@NogDogJan 03.2011 — #If using PHP 5.3.0+, you can use [url=http://www.php.net/manual/en/datetime.diff.php]DateTime::diff[/url](). Also, if working with database date information, it might be desirable to do it as part of the DB query, for instance using the MySQL [url=http://www.php.net/manual/en/datetime.diff.php]DATE_SUB() or DATE_ADD() functions[/url].