Home » Developer & Programmer » Reports & Discoverer » Find difference interm of HH24:MM:SS
Find difference interm of HH24:MM:SS [message #481788] Sat, 06 November 2010 11:01 Go to next message
shahzad-ul-hasan
Messages: 615
Registered: August 2002
Senior Member
i want to calculate the diffrence between the intime and outtime.pls see the table structure for further understanding.

Id intime: Outime: Date
10001 2-Nov-2010 12:23:00 2-Nov-2010 04:23:22 2-Nov-2010
  • Attachment: 1233.JPG
    (Size: 8.42KB, Downloaded 936 times)
Re: Find difference interm of HH24:MM:SS [message #481796 is a reply to message #481788] Sat, 06 November 2010 13:48 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> select substr(to_timestamp('2-Nov-2010 12:23:00','DD-MON-YYYY HH24:MI:SS')
  2                -
  3                to_timestamp('2-Nov-2010 04:23:22','DD-MON-YYYY HH24:MI:SS'),
  4                12, 8) res
  5  from dual
  6  /
RES
--------
07:59:38

Regards
Michel
Re: Find difference interm of HH24:MM:SS [message #481808 is a reply to message #481796] Sun, 07 November 2010 00:11 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 615
Registered: August 2002
Senior Member
but this query is not working because my datatype of column is varchar2.
pls advised.
Re: Find difference interm of HH24:MM:SS [message #481819 is a reply to message #481808] Sun, 07 November 2010 01:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And my inputs are strings (YOUR strings); where is the difference?

Regards
Michel

[Updated on: Sun, 07 November 2010 01:02]

Report message to a moderator

Re: Find difference interm of HH24:MM:SS [message #481824 is a reply to message #481819] Sun, 07 November 2010 01:48 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 615
Registered: August 2002
Senior Member
please see the attached file./forum/fa/8409/0/
  • Attachment: 122233.JPG
    (Size: 20.73KB, Downloaded 1475 times)
Re: Find difference interm of HH24:MM:SS [message #481828 is a reply to message #481824] Sun, 07 November 2010 04:15 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This is why you have to ALWAYS post your Oracle version, with at least 3 decimals (as well as a working Test case: create table and insert statements).

Regards
Michel
Re: Find difference interm of HH24:MM:SS [message #481837 is a reply to message #481828] Sun, 07 November 2010 09:40 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It seems that you'll have to do that a little bit harder.

If you use TO_DATE, then difference between two (date) values is a number of days:
SQL> select to_date('2-Nov-2010 12:23:00','DD-MON-YYYY HH24:MI:SS')
  2         -
  3         to_date('2-Nov-2010 04:23:22','DD-MON-YYYY HH24:MI:SS') res
  4  from dual;

       RES
----------
.333078704

Now you have to create hours, minutes and seconds - based on the previous result.

Number of hours: as day has 24 hours, simply multiply the previous result with 24:
SQL> select 0.333078704 * 24 hours from dual;

     HOURS
----------
 7.9938889
That makes 7 hours. The rest should be multiplied with 60 (as every hour has 60 minutes):
SQL> select 0.9938889 * 60 minutes from dual;

   MINUTES
----------
 59.633334
That's 59 minutes. In order to get seconds, multiply the rest with 60 (as every minute has 60 seconds):
SQL> select 0.633334 * 60 seconds from dual;

   SECONDS
----------
  38.00004

Finally, the result is the same as Michel's - you'll just need to compose it.

[EDIT: fixed " * 24" query - was "days" instead of "hours"]

[Updated on: Sun, 07 November 2010 23:59]

Report message to a moderator

Re: Find difference interm of HH24:MM:SS [message #481841 is a reply to message #481837] Sun, 07 November 2010 10:27 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I think the alias in the second query is HOURS not DAYS.

Regards
Michel
Re: Find difference interm of HH24:MM:SS [message #481874 is a reply to message #481841] Sun, 07 November 2010 23:58 Go to previous message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It appears that you think correctly Smile Sorry, my bad, I'll fix it right now.
Previous Topic: Report Key not found
Next Topic: How can i set vertical alignment in Report 6i
Goto Forum:
  


Current Time: Fri Apr 26 14:47:10 CDT 2024