Solved

Format Time Difference

Posted on 2008-06-10
6
201 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 22

Author Comment

by:Thomasian
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks, I didn't notice that.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
Read about achieving the basic levels of HRIS security in the workplace.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now