note 55567 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 15 Jan 2006 12:43:34 +0000 |
| Subject: | note 55567 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101832@lists.php.net to get a copy of this message | ||
Note Submitter: james dot baxter at november54 dot com
----
Heres something i've written to (a) figure the age from DOB in the sql format YYYY-MM-DD (b)
Check the member is over 18 which I need to do before allowing the content to be viewed.
$User_DoB contains the Date of Birth taken from the members database.
<?php
$DoB_Array = explode("-", $User_DoB);
$Today_Array = explode("-", date('Y-m-d'));
// _Array[0] is the year, _Array[1] is the month, _Array[2] is the day.
if ($Today_Array[1] > $DoB_Array[1] || ($Today_Array[2] >= $DoB_Array[2] &&
$DoB_Array[2] == $Today_Array[2])) {
$Age = $Today_Array[0] - $DoB_Array[0];
} else {
$Age = $Today_Array[0] - $DoB_Array[0] - 1;
}
if ($Age < 18) {
$Error[11] = 1;
}
?>
If the rest of the code found $Error[11] to have the value of 1 the user would be informed
they're not allowed to view the content and redirected to a "safe" page.
I think this is the best possible way I could have done it, if theres a better way please let me
know.