Calculating age based on date of birth in SQL and C#? [duplicate]
Possible Duplicates:
How to calculate age (in years) based on Date of Birth and getDate() How do I calculate someone’s age in C#? 开发者_如何学C
How to calculate the customer age automatically by using their Date of Birth using c# and SQL Server 2005
From here:
SELECT DATEDIFF(hour,@dob,GETDATE())/8766 AS AgeYearsIntTrunc
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 :)
Use a SQL function. See http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/399a7e87-bc78-47a5-8cc2-2d2436886fd7/
精彩评论