Solved

Format Time Difference

Posted on 2008-06-10
6
206 Views
Last Modified: 2010-04-21
What is the best way to return the time difference in nn:hh format?

Is there a better way to write this statement?

SELECT DATEDIFF("n",#1:13:44#,#2:45:33#) & FORMAT(#2:45:33# - #1:13:44#,":ss")

Note that this will not work:
SELECT FORMAT(#2:45:33# - #1:13:44#,":ss")
because it will not return a value greater than 60 minutes.
0
Comment
Question by:Thomasian
  • 3
  • 3
6 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 21749608
I don't really know what you mean by ' nn:hh format'.

If you want the time difference in hms then you can do:

FORMAT(#2:45:33# - #1:13:44#,"hh:mm:ss")
0
 
LVL 22

Author Comment

by:Thomasian
ID: 21750387
Most of the difference will be less than 1 hour. If I use "hh:nn:ss", most of the values (if not all) returned will have a value 0. That is why I want to combine the hour and minute value.

e.g.
A difference of 1:30:12 will be returned as 90:12
0
 
LVL 77

Expert Comment

by:peter57r
ID: 21750467
You cannot show an minute value greater than 59. It would produce an invalid time value.

If you want to show the result like that you will have to do some calculations and create a string to display the value.

cstr(DATEDIFF("s",#1:13:44#,#2:45:33#) \60 ) & ":" & cstr(DATEDIFF("s",#1:13:44#,#2:45:33#)  mod 60 )
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 22

Author Comment

by:Thomasian
ID: 21750492
Will that be better than the query I posted?

SELECT DATEDIFF("n",#1:13:44#,#2:45:33#) & FORMAT(#2:45:33# - #1:13:44#,":ss")
0
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 21750956
yes.
Datediff ("n",.......) will just look at the minute numbers so half the time you will get the wrong answer

DATEDIFF("n",#1:13:59#,#1:14:00#) gives 1 (minute)
0
 
LVL 22

Author Closing Comment

by:Thomasian
ID: 31465660
Thanks, I didn't notice that.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

770 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