[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Format Time Difference

Posted on 2008-06-10
6
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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