If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > count years

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-18-04, 00:30
Yuu Yuu is offline
Registered User
 
Join Date: Apr 2004
Posts: 6
count years

hi i want to know how to count years from dates...
so todays_date minus 14-Feb-1999 = 5 years....
right now im using
SELECT P.LAST_NAME as "Last Name",
((SYSDATE - P.DATE_LAST_UPDATED)/365) as "years"
FROM PATIENT P;

is there any way thats simpler than divide by 365?
thank you so much

Last edited by Yuu; 04-18-04 at 01:15.
Reply With Quote
  #2 (permalink)  
Old 04-18-04, 04:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
simpler? sure, several ways

the easiest is

select year(p.date_last_updated) - year(sysdate)

check your database for something like a DATEDIFF function too
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-18-04, 12:22
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally posted by r937
select year(p.date_last_updated) - year(sysdate)
While this is syntactically simpler, you can still run into problems if you don't consider whether the SYSDATE day of the year is before/after the day of the p.date_last_updated day of the year.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On