LoRz

Monday, June 30, 2008

 

Compute Age in PHP


Code to compute age in PHP

<?php

list($bYear, $bMonth, $bDay) = explode("-", $birthday);

$cMonth = date('n');
$cDay = date('j');
$cYear = date('Y');

if(($cMonth >= $bMonth && $cDay >= $bDay) || ($cMonth > $bMonth)) {
$age = $cYear - $bYear;
} else {
$age = 0;
}

echo $age;
?>

The date format in the code above is yyyy-mm-dd.

If you are to use mm/dd/yyy format change the code
list($bYear, $bMonth, $bDay) = explode("-", $birthday);
to
list($bMonth, $bDay, $bYear) = explode("/", $birthday);





<< Home

Archives

June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   May 2009   July 2009   September 2009   October 2009   WEC 44 live stream   UFC 106 live stream

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]