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 2012 Forums
 Transact-SQL (2012)
 t-sql 2012 calculate age

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-08-31 : 23:28:56
In a sql server 2012 database, I have a field called date of birth that is stored in a tha thatis stored in a datetime format. I need to determine the age of various students in the school system. Thus can you show me sql to that I can use to determine the a child is currently?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-01 : 03:50:39
[code]select age = datediff(year, [date of birth], getdate())
from yourtable[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-09-01 : 05:04:53
See http://www.sqlteam.com/article/datediff-function-demystified


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

smith_peter_uk
Starting Member

1 Post

Posted - 2014-09-07 : 11:36:17
Calculate age in year, month and days. Check this link:
http://subnol.blogspot.com/2014/09/how-to-calculate-age-in-sql-server.html
Go to Top of Page
   

- Advertisement -