Home » SQL & PL/SQL » SQL & PL/SQL » count hours between a date range (pl/sql)
count hours between a date range [message #403309] Thu, 14 May 2009 14:31 Go to next message
deahayes3
Messages: 203
Registered: May 2006
Senior Member

Hello everyone,

Is there an easy way to count number of hours between a date range? For example if 14-May-2009 08:00 to 14-May-2009 14:00 should return 6 hours. I was wondering if theres a time_between function like months_between. I really don't know how to get started on this one.

Any help is appreciated.
Re: count hours between a date range [message #403313 is a reply to message #403309] Thu, 14 May 2009 14:53 Go to previous messageGo to next message
BlackSwan
Messages: 25033
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
Go to the URL above click the link "Posting Guidelines"
Go to the section labeled "Practice" & do as directed.

Just subtract the dates & covert the results which are in units of days to hours.
Re: count hours between a date range [message #403315 is a reply to message #403309] Thu, 14 May 2009 15:06 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It seems you did learn nothing from your previous topic despite the number of answers explaining you in details how to handle Oracle dates:
http://www.orafaq.com/forum/m/402325/102589/#msg_402325

Maybe you should also read what is said about this datatype in SQL Reference.

Regards
Michel
Re: count hours between a date range [message #403352 is a reply to message #403309] Fri, 15 May 2009 00:11 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
SQL>select
  2  (to_date('1-jan-2009 12:00:00','dd-mon-yyyy hh:mi:ss') -
  3    to_date('1-jan-2009 5:00:00','dd-mon-yyyy hh:mi:ss'))*24 Hour_Diff
  4  from dual;

 HOUR_DIFF
==========
         7

1 row selected.

SQL>select
  2   (to_date('2-jan-2009 12:00:00','dd-mon-yyyy hh:mi:ss') -
  3     to_date('1-jan-2009 5:00:00','dd-mon-yyyy hh:mi:ss'))*24 Hour_Diff
  4   from dual;

 HOUR_DIFF
==========
        31

1 row selected.


regards,
Delna
Re: count hours between a date range [message #403428 is a reply to message #403352] Fri, 15 May 2009 09:52 Go to previous messageGo to next message
deahayes3
Messages: 203
Registered: May 2006
Senior Member

Thanks, that is exactly what I did.
Re: count hours between a date range [message #403433 is a reply to message #403428] Fri, 15 May 2009 10:16 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
deahayes3 wrote on Fri, 15 May 2009 16:52
Thanks, that is exactly what I did.

So why didn't you tell us?

Regards
Michel

Previous Topic: Subtract Positive values to negative values
Next Topic: String and Numeric Manipulation
Goto Forum:
  


Current Time: Sat Dec 03 01:14:22 CST 2016

Total time taken to generate the page: 0.22353 seconds