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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top