Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having problem with DATEDIFF

Status
Not open for further replies.

limester

Technical User
Dec 29, 2004
69
CA
Hi,

I am trying to calculate a persons age using DATEDIFF. I have a column birthdate (ANSII format yyyy.mm.dd).

This is my query that is failing:

select datediff('year', birthdate, now()) from table1 where table1.column1 = 'value'

Can anyone help me modify this to get the age (in years)?

Thanks.
 
Sorry syntax error, was not supposed to use the single quotes for year.

Thanks.
 
Thanks earth and fire.

My query worked fine once I removed the quotes from the year. I also made a modification so that the date is more accurate and will compensate for a leap year:

convert(int, Datediff(dd, birth_date, getdate())/365.25)

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top