Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 calculate Age

Author  Topic 

Hus
Starting Member

4 Posts

Posted - 2011-07-13 : 16:24:29
Hi
I want to calculate age between two dates.
E.g
ID DOB
22 01-01-2009
23 04-04-2010
34 05-05-2010

Reporting period between 01-04-2011 and 30-06-2011.

Can someone assist me, I want to know how clients are age 1 between the reporting period.

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-07-13 : 16:28:28
Select * From table Where dateadd(yy,1,DOB) between '04/01/2011' and '06/30/2011'

or if your dateformat looks like:
Select * From table Where dateadd(yy,1,DOB) between '01/04/2011' and '30/06/2011'

Corey

I Has Returned!!
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-07-13 : 16:46:50
Computing the age of someone is more difficult than it might seem when you take into account different month lengths, leap year, and other things.

This function returns age in format YYYY MM DD.
Age Function F_AGE_YYYY_MM_DD:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729

This function returns age in years.
Age Function F_AGE_IN_YEARS:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462






CODO ERGO SUM
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-07-13 : 17:10:51
quote:
Originally posted by Michael Valentine Jones

Computing the age of someone is more difficult than it might seem when you take into account different month lengths, leap year, and other things.

This function returns age in format YYYY MM DD.
Age Function F_AGE_YYYY_MM_DD:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729

This function returns age in years.
Age Function F_AGE_IN_YEARS:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462






CODO ERGO SUM



Yes... calculating the Age is more complicated, but he didn't really ask for that.

He asked for the people are age 1 during that period of time... I took that to mean:
"People who turn 1 during the period"

I suppose it could also mean:
"People who were atleast 1 and less than 2 during the period"

Either way, the exact age shouldn't really be necessary.

Corey

I Has Returned!!
Go to Top of Page
   

- Advertisement -