Return to Snippet

Revision: 32471
at September 26, 2010 01:31 by nilambar


Initial Code
/*
*	calculateAge()
*	@action: calculate age from given date
*	@params:
*		birthday: birthday in format YYYY-MM-DD
*	@return: age (integer 	)
*	@modified : 27 August 2010
*	@modified by: Sucl Tandukar
*/
function calculateAge ($birthday)
{
	list($year,$month,$day) = explode("-",$birthday);
	$year_diff  = date("Y") - $year;
	$month_diff = date("m") - $month;
	$day_diff   = date("d") - $day;
	if ($day_diff < 0 || $month_diff < 0)
		$year_diff--;
	return $year_diff;
}

Initial URL

                                

Initial Description
Calculate age; given date.

Initial Title
Calculate Age in PHP; given date of birth

Initial Tags
php

Initial Language
PHP