We help IT Professionals succeed at work.

Access query to calculate time between 2 dates

68 Views
Last Modified: 2019-02-20
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

CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT

Commented:
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]
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
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...
CERTIFIED EXPERT
Expert of the Year 2019
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...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
thanks all !!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions