Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > SQL Date Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-19-02, 07: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, 08: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 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

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