Avatar of Fordraiders
Fordraiders
Flag for United States of America asked on

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
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
ITguy565

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])
Fordraiders

ASKER
Sorry, I need the query revised for sql server not Access
ITguy565

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]
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Bill Prew

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

CONVERT(time, Date1-Date2)

Open in new window


»bp
Fordraiders

ASKER
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
Fordraiders

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Bill Prew

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


»bp
Fordraiders

ASKER
sorry 15 sec
ASKER CERTIFIED SOLUTION
Bill Prew

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fordraiders

ASKER
thanks all !!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy