Access query to calculate time between 2 dates

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
LVL 3
FordraidersAsked:
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.

ITguy565Commented:
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])
FordraidersAuthor Commented:
Sorry, I need the query revised for sql server not Access
ITguy565Commented:
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]
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Bill PrewIT / Software Engineering ConsultantCommented:
In SQL Server you can get the time difference between two datetime values by doing:

CONVERT(time, Date1-Date2)

Open in new window


»bp
FordraidersAuthor 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
FordraidersAuthor 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 PrewIT / Software Engineering ConsultantCommented:
Not sure how you came up with the 55, but are subtracting the smaller from the larger?


»bp
FordraidersAuthor Commented:
sorry 15 sec
Bill PrewIT / Software Engineering ConsultantCommented:
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

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
FordraidersAuthor Commented:
thanks all !!
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
SQL

From novice to tech pro — start learning today.