Hi everyone.
I have a table [tblEmployee] from which I need to calculate the employees' ages and lengths of service from the fields [DateOfBirth] and [DateJoined].
For the Age Calculation
I have successfully used an expression that I found in these forums (see the query in the attached Access 2k database):
Age: DateDiff("yyyy",[DateOfBirth],Date())+Int(Format(Date(),"mmdd")<Format([DateOfBirth],"mmdd"))
It correctly returns the employees' ages as at the current system date.
But I would like to make it more flexible. I want to convert it into a public function so that it can calculate the age as at a specified date. And if the date is not specified, then calculate the age as at the current system date. Can it be done?
For the Calculation of Length of Service
Similar to the age calculation, I would like to have a public function that can return the length of service as at a specified date, or at the current system date if the date is not specified.
To show what I need, I have manually entered in the table the Lengths of Service as at Dec 1 2003. They are based on the calendar dates, so that, for an employee whose [DateJoined] is Dec 1 2002, the length of service as at Dec 1 2003 would be "1 Yr 0 mon 1 day".
I should appreciate any help.
Thanks in advance.
Rose
I have a table [tblEmployee] from which I need to calculate the employees' ages and lengths of service from the fields [DateOfBirth] and [DateJoined].
For the Age Calculation
I have successfully used an expression that I found in these forums (see the query in the attached Access 2k database):
Age: DateDiff("yyyy",[DateOfBirth],Date())+Int(Format(Date(),"mmdd")<Format([DateOfBirth],"mmdd"))
It correctly returns the employees' ages as at the current system date.
But I would like to make it more flexible. I want to convert it into a public function so that it can calculate the age as at a specified date. And if the date is not specified, then calculate the age as at the current system date. Can it be done?
For the Calculation of Length of Service
Similar to the age calculation, I would like to have a public function that can return the length of service as at a specified date, or at the current system date if the date is not specified.
To show what I need, I have manually entered in the table the Lengths of Service as at Dec 1 2003. They are based on the calendar dates, so that, for an employee whose [DateJoined] is Dec 1 2002, the length of service as at Dec 1 2003 would be "1 Yr 0 mon 1 day".
I should appreciate any help.
Thanks in advance.
Rose