Anatoly Lubarsky

Logo
MSSQL, .NET, Design. Life and Music

T-SQL: Get Age from Date of Birth

I just like tiny SQL tricks. Once I posted how to Get only Date from DateTime without performing any casting or conversion.


So...


Sometimes it is useful for social oriented networks to calculate on the fly or store user age given his/her date of birth. Below is a small snippet in T-SQL:

SELECT FLOOR(DATEDIFF(DAY, @BirthDate, @TargetDate) / 365.25)

Related Posts:

Friday, August 10, 2007 6:15 PM

Comments

# Interesting Finds: August 11, 2007

8/11/2007 8:05 AM by Jason Haley

# re: T-SQL: Get Age from Date of Birth
Don't forget to take into account leap years

http://www.sqlmag.com/Article/ArticleID/96418/sql_server_96418.html

8/11/2007 9:21 PM by Tom Pester

# re: T-SQL: Get Age from Date of Birth
Tom: What about leap years ?
Do you have any example this does not work ?

8/11/2007 9:48 PM by Anatoly Lubarsky

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)