Calculate time difference

1. Member
Join Date
Dec 1969
Posts
69

## Calculate time difference

Hi-<BR><BR>I have a table with a start time and end time. The difference between the two will almost always be hours and minutes. I&#039;m trying to get the results to be formatted as hours and minutes, but can&#039;t find anything about how to do this in ASP or T-SQL. The database is sql server 7. <BR><BR>Any ideas on how I can accomplish this?<BR><BR>Thanks.

2. Senior Member
Join Date
Dec 1969
Posts
1,843

.

3. Member
Join Date
Dec 1969
Posts
69

## can't get datediff to work like I need it to

If the difference between the two times is 83 minutes, I can only get datediff to return either 83 minutes, or 1 hour. I need the results to be 1 hour, 23 minutes.<BR><BR>Thanks.

4. Senior Member
Join Date
Dec 1969
Posts
1,843

## RE: can't get datediff to work like I need it

Use seconds, then divide.

5. Senior Member
Join Date
Dec 1969
Posts
1,843

## RE: can't get datediff to work like I need it

Or use minutes for that matter.

6. Member
Join Date
Dec 1969
Posts
69

## RE: can't get datediff to work like I need it

Well, when I divide it by minutes it truncates it to 1 hour.

7. Senior Member
Join Date
Dec 1969
Posts
1,843

## Huh? Simple math.........

Let&#039;s say your datediff is 83 minutes. <BR><BR>83/60 = 1<BR><BR>83 - (60*1) = 23<BR><BR>1:23<BR><BR>Or, in ASP. <BR><BR>Difference = DateDiff("H",DateOne,DateTwo)<BR><BR>HoursDiff = Difference / 60<BR><BR>MinDiff = Difference - (60*HoursDiff)<BR><BR>Difference = HoursDiff&":"&MinDiff

8. Member
Join Date
Dec 1969
Posts
69

## Well, since you put it THAT way...

it is simple, but I couldn&#039;t figure it out for the life of me.<BR><BR>Thank you!

9. Senior Member
Join Date
Dec 1969
Posts
1,843

## actually..

you have to have one more step, because 83/60 isn&#039;t actually one, of course. <BR><BR><BR>Difference = DateDiff("H",DateOne,DateTwo)<BR><BR>HoursDiff = Int(Difference / 60)<BR><BR>MinDiff = Difference - (60*HoursDiff)<BR><BR>Difference = HoursDiff&":"&MinDiff<BR><BR><BR>The Int() will turn 1.xxx into just 1<BR>

10. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: actually..

(Datediff("n", date1, date2) 60) & ":" & (Datediff("n", date1, date1)Mod 60)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•