Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350598

Summary: Javascript function to convert birthday to age
Product: z_Archived Reporter: Sascha Vogt <sascha>
Component: BIRTAssignee: Birt-Data-inbox <Birt-Data-inbox>
Status: NEW --- QA Contact: Xiaoying Gu <bluesoldier>
Severity: enhancement    
Priority: P3 CC: bluesoldier
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Sascha Vogt CLA 2011-06-28 11:20:46 EDT
Build Identifier: 3.7.0.v20110603-BDF9E7AGTzuHfngz-8A08WvWDv8v

It would be great to have a built in Javascript function which converts dates to an age. 

Reproducible: Always
Comment 1 Sascha Vogt CLA 2011-06-28 11:24:53 EDT
I used the following snippet to convert the birthday from format dd.mm.YY to an age

function getAge(birthday)
{
if(birthday==null)
	return
tmpYear = birthday.substr(6,2)
if(tmpYear>11)
	year = "19"+tmpYear
else
	year = "20"+tmpYear
month = birthday.substr(3,2)
day = birthday.substr(0,2)

today = BirtDateTime.today()
fixedBirthday = year + "-" + month + "-" + day
age = BirtDateTime.diffYear(fixedBirthday, today)
if(BirtDateTime.month(today)<month)
	age = age - 1
else if (BirtDateTime.month(today)==month)
{
	if(BirtDateTime.day(today)<day)
		age = age - 1
}

return age
}

I'm sure, this can be done better - but some sort of function would be great to have in core birt