Hello all,
I need to add Year & Months to a persons age from a
datetime (DoB) field. The current script I have (as below)
can calculate only Years but NOT months. Does anyone have
any idea or a ready script that I can use which will give
me months & years for that person using the Dob field?
CASE
WHEN DATEADD(year, DATEDIFF (year, p1.DOB, getdate()),
p1.DOB) > getdate()
THEN DATEDIFF (year, p1.DOB, getdate()) - 1
ELSE DATEDIFF (year, p1.DOB, getdate())
END as 'Age'
Thanks much in advance,
JoshiSee if this helps:
[url]http://www.alegsa.com.ar/Visitas/i45/Calculating%20yrs%20&%20mths%20for%20age.php[
/url]
AMB
"J. Joshi" wrote:
> Hello all,
> I need to add Year & Months to a persons age from a
> datetime (DoB) field. The current script I have (as below)
> can calculate only Years but NOT months. Does anyone have
> any idea or a ready script that I can use which will give
> me months & years for that person using the Dob field?
> CASE
> WHEN DATEADD(year, DATEDIFF (year, p1.DOB, getdate()),
> p1.DOB) > getdate()
> THEN DATEDIFF (year, p1.DOB, getdate()) - 1
> ELSE DATEDIFF (year, p1.DOB, getdate())
> END as 'Age'
> Thanks much in advance,
> Joshi
>|||Substracting the integer representation of the date of birth's month value
from the integer representation of current month value will give you the
number of months you are looking for.
Anith
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment