3

Possible Duplicates:
How to calculate age (in years) based on Date of Birth and getDate()
How do I calculate someone’s age in C#?

How to calculate the customer age automatically by using their Date of Birth using c# and SQL Server 2005

Community
  • 1
  • 1
Raj
  • 31
  • 1
  • 1
  • 2

3 Answers3

3

From here:

SELECT DATEDIFF(hour,@dob,GETDATE())/8766 AS AgeYearsIntTrunc
Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
1

I found this on Google: SELECT FLOOR(DATEDIFF(DAY, @BirthDate, @TargetDate) / 365.25)

Where @TargetDate is the date of today (GETDATE() in TSQL).

Good luck :)

Anemoia
  • 7,928
  • 7
  • 46
  • 71
  • This simple but not precise. For example a person born on 29 -May-1992 would be 17 on 29-May-2009, but this formula returns 16. See my URL http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/399a7e87-bc78-47a5-8cc2-2d2436886fd7/ – Daveo May 25 '10 at 06:25
0

Use a SQL function. See http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/399a7e87-bc78-47a5-8cc2-2d2436886fd7/

Daveo
  • 19,018
  • 10
  • 48
  • 71