how to get the age from sql?

  • Thread starter Thread starter Guest
  • Start date Start date
You'll need to use the datediff function. You can't compare dates directly
like you can integers. You'll also need to supply which datepart you're
looking for, year, month, day, etc..
 
Look up Datediff in books online:
Select
DateDiff(yy,Cast('10/21/1970' as DateTime),Getdate()) AgeYears,
DateDiff(mm,Cast('10/21/1970' as DateTime),Getdate()) AgeMonths,
DateDiff(dd,Cast('10/21/1970' as DateTime),Getdate()) AgeDays,
DateDiff(ww,Cast('10/21/1970' as DateTime),Getdate()) AgeWeeks,
DateDiff(hh,Cast('10/21/1970' as DateTime),Getdate()) AgeHours,
DateDiff(mi,Cast('10/21/1970' as DateTime),Getdate()) AgeMinutes,
DateDiff(ss,Cast('10/21/1970' as DateTime),Getdate()) AgeSeconds,
DateDiff(qq,Cast('10/21/1970' as DateTime),Getdate()) AgeQuarters
 
Back
Top