note 115846 added to function.date-diff
| From: | jesushuertaarrabal at gmail dot com | Date: | Fri, 03 Oct 2014 00:48:45 +0000 |
| Subject: | note 115846 added to function.date-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200573@lists.php.net to get a copy of this message | ||
A way to verify a correct date getting your age
if (isset($_POST['birthday'])){
if (preg_match("/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$/",$_POST['birthday'])){
$items = explode("-", $_POST['birthday']);
if (checkdate($items[1], $items[2], $items[0])){ //checkdate(m-d-y)
//If you were born in a lip-year or lip - 1, then we have to add 5 days, else, we add
4 days
if ((0 == $items[0] % 4) && (0 != $items[0] % 100) || (0 == $items[0] % 400))
$bis = 4;
else
$bis = 5;
if (date_diff(date_create($_POST['birthday']) ,
date_create(date('Y-m-d')))->format("%R%a days") > (6569 + $bis)) //365*18
$print .= 'Birthday date: ' . $_POST['birthday'] .
'<br>';
else
$error[] = -1;
}else
$error[] = -2;
}else
$error[] = -3;
}else
$error[] = -4;
}
----
Server IP: 80.64.47.13
Probable Submitter: 217.127.230.149
----
Manual Page -- http://php.net/manual/en/function.date-diff.php
Edit -- https://master.php.net/note/edit/115846
Del: integrated -- https://master.php.net/note/delete/115846/integrated
Del: useless -- https://master.php.net/note/delete/115846/useless
Del: bad code -- https://master.php.net/note/delete/115846/bad+code
Del: spam -- https://master.php.net/note/delete/115846/spam
Del: non-english -- https://master.php.net/note/delete/115846/non-english
Del: in docs -- https://master.php.net/note/delete/115846/in+docs
Del: other reasons-- https://master.php.net/note/delete/115846
Reject -- https://master.php.net/note/reject/115846
Search -- https://master.php.net/manage/user-notes.php