How to calculate the hours between StartDate and EndDate


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.

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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


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
 from your table )


mrongAuthor Commented:
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

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.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.