开发者

Calculating age based on date of birth in SQL and C#? [duplicate]

This question already has answers here: Closed 12 years ago.

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜