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

Subtracting 2 dates and getting hour and min as out put

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I want to make a script that subtract 2 date from each other, and returns how many hours and minutes there are between the 2 dates.

I made this script that seems to work but gives a funny output

This is the select sentence
select (to_date('2002 Aug 26 13 22','YYYY Mon DD HH24 MI') - to_date('20020826 1321 ','YYYYMMDD HH24MI')) from dual;

The output is this:
(TO_DATE('2002AUG261322','YYYYMONDDHH24MI')-TO_DATE('200208261321','YYYYMMDDHH24
--------------------------------------------------------------------------------
.000694444


I'd like the script to return the number of hour and minutes between the dates.


Thanks.
 
If you multiply the result of your query by 86400 (The number of seconds in a day, you'll get the number of seconds difference of your subtraction.

The above computes to 59.9999616

Naturally, multiplying then by 60 will compute minutes, and so on ....

AA 8~)
 
[pc3]
select trunc(sysdate-to_date('09.06.2002 22:59:30','dd.mm.yyyy hh24:mi:ss'))||' days' days_between
,'and '||to_char(
to_date (
mod(
(86400*(
sysdate-to_date('09.06.2002 22:59:30','dd.mm.yyyy hh24:mi:ss'))
),86400)
,'sssss')
,'hh24:mi:ss') hours_minutes_seconds from dual

I hope that it will be helpfull to you. [pipe] web/sql developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top