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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Current Age

Status
Not open for further replies.
Jan 28, 2004
19
US
I have a sql database that is capturing DOB in this format: mm/dd/yyyy eg. 01/01/1980. my goal is to use a sql statement to display individuals who are >=60.

My statement is as follows:
Select *
from members
where cast ( 'TODAY' as DATE) - cast ( m.dob as DATE) /365.25 >=60,1,0


Thanks again for your help.


 
This tells me I'm 28

Code:
SELECT CAST(NOW() AS DATE)- STR_TO_DATE('10/13/1981', '%m/%d/%Y');

Can you figure it out from there? I don't want to have all the fun.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Code:
SELECT YEAR(CURRENT_DATE) 
       - YEAR(m.dOB)
       - CASE WHEN MONTH(CURRENT_DATE)
                 > MONTH(m.dOB)      
              THEN 0
              WHEN MONTH(CURRENT_DATE)
                 < MONTH(m.dOB)      
              THEN 1
              WHEN DAY(CURRENT_DATE)
                 < DAY(m.dOB) 
              THEN 1
              ELSE 0 END    AS age
  FROM ...
:)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top