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

Date Difference in HOURS 1

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
0
0
US
I have two datetime fields.

I need to calculate the difference in HOURS.

Example:

DATE1 = 2/22/2004 5:00 PM
DATE2 = 2/23/2004 6:30 PM

DIFFERENCE = 25.5 HOURS

How can I do this?


Thanks,

Leo ;-)
 
Leonel,

Aquí está una solución a su pregunta:

SQL> select (to_date('02/23/2004 06:30 PM','mm/dd/yyyy hh:mi pm')
2 -to_date('02/22/2004 05:00 PM','mm/dd/yyyy hh:mi pm')) / (1/24) Hours_Diff
3 from dual
4 /

HOURS_DIFF
----------
25.5

1 row selected.

Díganos si esto es lo que usted quiso.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 00:49 (24Feb04) UTC (aka "GMT" and "Zulu"), 17:49 (23Feb04) Mountain Time)
 
Step1:
create or replace FUNCTION time_diff (x DATE, y DATE) RETURN varchar2 IS
BEGIN
return substr (LPAD (ABS (ROUND ( (x - y) * 24)) , 2, '0')||':'||
LPAD (ABS ( round( ( ( ( x - y ) * 24 ) - round ( ( x - y ) * 24 ) ) * 60 ) ) , 2, '0' ),1,5);
END;

Step2:
select time_diff (x, y) from dual;


For further queries:
amirak17@yahoo.com

Regards,
Amir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top