What would be the best way to calculate someone\'s age in years, months, and days in T-SQL (SQL Server 2000)?
The datediff
function doesn\'t handle year
DateTime
values in T-SQL are stored as floats. You can just subtract the dates from each other and you now have a new date that is the timespan between them.
declare @birthdate datetime
set @birthdate = '6/15/1974'
--age in years - short version
print year(getdate() - @birthdate) - year(0)
--age in years - visualization
declare @mindate datetime
declare @span datetime
set @mindate = 0
set @span = getdate() - @birthdate
print @mindate
print @birthdate
print getdate()
print @span
--substract minyear from spanyear to get age in years
print year(@span) - year(@mindate)
print month(@span)
print day(@span)