note 34096 added to ref.datetime
| From: | menaurus at gmx dot de | Date: | Wed, 16 Jul 2003 09:37:12 +0000 |
| Subject: | note 34096 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52174@lists.php.net to get a copy of this message | ||
The argument has to be in the standard mysql format (y-m-d)...
function age($date) {
if (!$date) return false;
$year=0+substr($date,0,4);
$month=0+substr($date,5,2);
$day=0+substr($date,8,2);
$t=0;
$d=date("d");
$m=date("m");
$y=date("Y");
$age=$y-$year;
if ($m<$month) $t=-1;
else if ($m==$month) if ($d<$day) $t=-1;
return ($age+$t);
}
this funktion has got a little bug:
On Line 12 and 13...
Bugfix:
12 if ($month<$m) $t=-1;
13 else if ($m==$month AND $day<$d) $t=-1;
----
Manual Page -- http://www.php.net/manual/en/ref.datetime.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34096
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34096&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34096&report=yes