SQL: Is there a more efficient way to calculate elapsed hours, minutes, seconds?

In terms of finding the hours, minutes, and seconds between two dates similar to the functions you are using, you could use DatePart like so.

In terms of finding the hours, minutes, and seconds between two dates similar to the functions you are using, you could use DatePart like so: DatePart(hh, Finish - Start) DatePart(mi, Finish - Start) DatePart(s, Finish - Start).

This answer is correct for minutes and seconds, per the details of the question -- but note that the hours (as of 5/21/2010) in the answer does not give total hours as the question intended... but this answer provides the elegant solution for grabbing the remainder minutes & seconds that I was looking for – hamlin11 May 22 '10 at 4:25 @hamlin11 - Your calculation of hours is the total hours difference between the two datetimes but that is very different than the hours portion (or minutes or seconds) of the difference which is what I presumed you were trying to get to. If you want the difference in hours between two dates you should simply use DateDiff(hh, Date1, Date2). I would think you would want the three values to represent the same thing (i.e.

Total hours, total min, total seconds or the diff's hour portion, min portion, sec portion). – Thomas May 22 '10 at 5:43 I understand where you were coming from. I was just making a distinction between your answer (what most people will come here looking for) and what my specific question was asking for.

Good answer, thanks – hamlin11 May 22 '10 at 14:13.

If you are using sql server, you can use datediff(minute,Start,Finish) datediff(hour,Start,Finish).

Does your dialect of SQL support this syntax for date interval math: db=> select to_char(timestamp '2010-05-21 10:10:10' - '2009-10-11', 'ddd hh24:mi:ss'); to_char -------------- 222 10:10:10 (1 row) db=> select to_char(timestamp '2010-05-21 10:10:10' - '2001-10-11', 'ddd hh24:mi:ss'); to_char --------------- 3144 10:10:10 (1 row) db=> select to_char(timestamp '2010-05-21 10:10:10' - '2010-05-21', 'ddd hh24:mi:ss'); to_char -------------- 000 10:10:10 (1 row).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions