SQL Need to calculate age from DOB, no stored procedures or functions or views

Charles Baldo
Charles Baldo used Ask the Experts™
on
I need to calculate age from today in years.   The date is stored in a Varchar(255)  type.   It has a format like  YYYY-mm-dd  ex 1971-02-12.  I am guaranteed it will always be a valid date.  The database version is SQL 2005.

This  must be in T-SQL I can not create a store procedure , function or view.  It is part of an upgrade of an FDA validated database and can not create new.  Don't like it but that's the government regulating.  I know this is easier to do with a function, have down it before with functions.  Do not have that ability at the moment

Thank You
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
select datediff(hour,'1992-04-09',getdate())/8766  'this is trunc version

select CONVERT(int,ROUND(DATEDIFF(hour,'1992-04-09',GETDATE())/8766.0,0))   ' this is TRUNC version

if you run this two you can see they can ve difference between them you choose the best one for your case. (if you use earlier monthsthen both give the same result)
Charles BaldoSoftware Developer

Author

Commented:
Thank You. With a few mods that worked.
PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
You might find this article useful.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial