note 22088 deleted from function.date by victor
| From: | victor@php.net | Date: | Sat, 24 Aug 2002 15:51:29 +0000 |
| Subject: | note 22088 deleted from function.date by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-35524@lists.php.net to get a copy of this message | ||
A simple php script with no java or vbscript to compare a date field from a mysql database to the
current date. In this case the date for comparison is $birthday (YYYY-MM-DD) and the output is
$age...
<?php
$today = getdate();
$month = $today['mon'];
$day = $today['mday'];
$year = $today['year'];
list ($byear, $bmonth, $bday) = split ('-', $birthday);
$rawage = $year-$byear;
if ($month < $bmonth)
{$age = $rawage-1;}
elseif ($month == $bmonth AND $day < $bday)
{$age = $rawage-1;}
elseif ($byear == 0)
{$age = "Unknown";}
else
{$age = $rawage;}
?>