Calculate age from date of birth


function getAge(dob){
	var dyr = -1;
	var dmo;

	if(dob){
		var tod = @Today();
		
		dyr = @Year(tod) - @Year(dob)
		dmo = @Month(tod) - @Month(dob)
		if( dmo < 0 || (dmo = 0 && @Day(tod) < @Day(dob) )) {
			dyr = dyr - 1;
		}
	}
	return @Text(@Integer(dyr));
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...