?
Solved

How to calculate the hours between StartDate and EndDate

Posted on 2004-12-01
8
Medium Priority
?
669 Views
Last Modified: 2013-12-26
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.

Thanks in advance.
0
Comment
Question by:mrong
5 Comments
 
LVL 8

Accepted Solution

by:
Vikas_Dixit earned 80 total points
ID: 12720718
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

by:diasroshan
diasroshan earned 80 total points
ID: 12723431
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

by:gajender_99
gajender_99 earned 80 total points
ID: 12724290
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
 from your table )


thanks

0
 

Author Comment

by:mrong
ID: 12725352
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

by:gajender_99
ID: 12733928
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question