note 55567 added to function.date
| From: | james dot baxter at november54 dot com | Date: | Sun, 07 Aug 2005 20:04:37 +0000 |
| Subject: | note 55567 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93207@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55567
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55567&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55567&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55567&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55567&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55567&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55567&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55567&report=yes
Search -- http://master.php.net/manage/user-notes.php