Solved

# How to calculate the hours between StartDate and EndDate

Posted on 2004-12-01
625 Views
Hello,

I created a query in PB9.0 which pull out the record from an Oracle DB. There are two fields StartDate and EndDate in 1/1/2003 00:00:00 format. I want to use EndDate-StartDate to get the time.

0
Question by:mrong

LVL 8

Accepted Solution

Hello,

Doing it in sql will be easy :

select (end_date - start_date)*24 HOURS from your_table;

You will get the no of hours between end_date and start_date.
Regards,
Vikas
0

LVL 18

Assisted Solution

HI,

thru PB scripting u can use the function DaysAfter as follows....

Long ll_days, ll_hours

ll_days DaysAfter(1999-12-20, 1999-12-24)
ll_days returns 4:

so the number of hours would be...
ll_hours = ll_days * 24

Cheers,
Rosh
0

LVL 8

Assisted Solution

HI,

As said by Vikas its much easier to do in SQL in Oracle but what Vikas have said will return the difference rounding to 100
i.e  9:45 hrs would be returned as 9:75

if you want the sql to return 9:45 try this

select TRUNC(ROUND(DUR,2))||':'|| TRUNC(mod((dur*60),60))
from (
select TO_NUMBER(end_date - start_date) *24 dur

thanks

0

Author Comment

Hi.
I use ROUND((Enddtm-Startdtm)*24,2) for the  following period. but I got 5.97. why?

StartDate: 2/3/2003 12:32:00
EndDate: 2/3/2003 18:30:00

Thanks.
0

LVL 8

Expert Comment

hi mrong

when you are using round it will round the number to the hundreth position
if you see my sql in the first part i am just taking the hours out and  and minutes sepratly and then joining them to get the result

if you need help in creating the function just let us know.

gajender

0

## Featured Post

### Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.