Access query to calculate time between 2 dates

Fordraiders
Fordraiders used Ask the Experts™
on
Access query to calculate time between 2 date/time stamp
for sql server

What I need : to get the time elapsed hh:mm:ss between, 2 fields
[OPENED_AT],[inprogress_or_closed_at]



SELECT ID_Racfid, 
Seller_Name, 
Track_Name, 
Activity_Task, 
Notes, 
Closed_Date, 
NSC_ID_Ref, 
opened_at, 
inprogress_or_closed_at, 
DateDiff("h",[OPENED_AT],[inprogress_or_closed_at]) AS Hours, 
DateDiff("n",[OPENED_AT],[inprogress_or_closed_at]) AS Minutes, 
ElapsedTime([OPENED_AT],[inprogress_or_closed_at]) AS [Duration Elapsed], 
TotalTime([OPENED_AT],[inprogress_or_closed_at]) AS [Duration Total]
FROM DataEntry 

Open in new window



thanks
fordraiders
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
https://support.office.com/en-us/article/calculate-the-number-of-days-between-two-dates-e73f4810-ea5b-4f82-86cd-93853f8029bd

this should be what you are looking for :

Right-click the form in the Navigation Pane and then click Layout View.
Click Design > Text Box, hold down the Ctrl key, and then click on the layout where you want to put the text box.
Click the new text box, and press F4 to display the Property Sheet if it's not already displayed.
On the Data tab of the Property Sheet, in the Control Source property box, type the following:
=DateDiff("d",Date(),[DueDate])

Author

Commented:
Sorry, I need the query revised for sql server not Access
declare @StartDate datetime, @EndDate datetime

select @StartDate = '10/01/2012 08:40:18.000',@EndDate='10/04/2012 09:52:48.000'

select convert(varchar(5),DateDiff(s, @startDate, @EndDate)/3600)+':'+convert(varchar(5),DateDiff(s, @startDate, @EndDate)%3600/60)+':'+convert(varchar(5),(DateDiff(s, @startDate, @EndDate)%60)) as [hh:mm:ss]
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
In SQL Server you can get the time difference between two datetime values by doing:

CONVERT(time, Date1-Date2)

Open in new window


»bp

Author

Commented:
SELECT [NSC_ID_Ref]
      ,[opened_at]
      ,[inprogress_or_closed_at]
 ,DateDiff(hh,[OPENED_AT],[inprogress_or_closed_at]) AS Hours
,DateDiff(mm,[OPENED_AT],[inprogress_or_closed_at]) AS Minutes
,DateDiff(ss,[OPENED_AT],[inprogress_or_closed_at]) AS Seconds

  FROM [flow].[dbo].time_entry]

this is working but getting an overflow error:

BUT YES, i NEED THE CALCULATION in ONE field

Author

Commented:
Bill,
Yours is returning:
opened_at                                 inprogress_or_closed_at             time                              should be
2016-02-09 07:33:23.000        2016-02-09 07:33:38.000             23:59:45.0000000        00:00:15
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Not sure how you came up with the 55, but are subtracting the smaller from the larger?


»bp

Author

Commented:
sorry 15 sec
Test your restores, not your backups...
Top Expert 2016
Commented:
So this seems to work and give :15

select CONVERT(time, CONVERT(datetime, '2016-02-09 07:33:38.000', 120) - CONVERT(datetime, '2016-02-09 07:33:23.000', 120));

Open in new window


»bp

Author

Commented:
thanks all !!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial