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 > Database Server Software > Oracle > SQL Date Query

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-19-02, 08:33
ravikr ravikr is offline
Registered User
 
Join Date: Jul 2002
Location: india
Posts: 2
SQL Date Query

Hi all,
i have a table like this
create table test
(
appln varchar2(50), -- application name
applndt date, -- stores application created date
upddt date --stores application last updated date)
/


I have inserted records as follows

insert into test values('app1',to_date('01-jan-1990 10:30:00','dd-mon-yyyy hh:mi:ss'),to_date('19-sep-2002 03:00:00','dd-mon-yyyy hh:mi:ss'));

insert into test values('app2',to_date('01-jan-1995 10:30:00','dd-mon-yyyy hh:mi:ss'),to_date('19-sep-2002 03:00:00','dd-mon-yyyy hh:mi:ss'));

Now I want a query which displays the output as follows

app1 12 years 8 Months 18 days 4 hrs 30 min
app2 7 years 8 months 18 days 4 hrs 30 min

how do i write a query to get the above output

regards
Ravi
Reply With Quote
  #2 (permalink)  
Old 09-19-02, 09:42
pre4711 pre4711 is offline
Registered User
 
Join Date: Sep 2002
Location: Austria
Posts: 37
Re: SQL Date Query

to give you a hint: have a look at:

select appln,
upddt-applndt as TotalDaysgone,
MONTHS_BETWEEN (upddt,applndt) as Totalmonthsgone,
trunc(MONTHS_BETWEEN (upddt,applndt)/12) as Yearsgone,
MONTHS_BETWEEN (upddt,applndt) - trunc(MONTHS_BETWEEN (upddt,applndt)/12)*12 as RestOfMonths,
trunc(MONTHS_BETWEEN (upddt,applndt) - trunc(MONTHS_BETWEEN (upddt,applndt)/12)*12) as Monthsgone
from test;

you could/would need the same nesting for days and hours etc.
personally I would rather write a stored procedure (or package) to achieve the same job.
rgds
Reply With Quote
Reply

Thread Tools
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