1. Senior Member
Join Date
Dec 1969
Posts
130

I asked about Datediff earlier, and I think I received a good answer. I guess my only other question is this..<BR>If I do a datediff between two values, and i use the "m" interval...how can i display the value returned in hours:minutes:seconds format?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

How about this for a hint:<BR><BR>***** timeDemo.asp *********<BR>&#060;HTML&#062;&#060;BODY&#062;<BR>< BR>&#060;%<BR>dt = TimeSerial( 0, 0, 17366 )<BR>%&#062;<BR>Time is &#060;% = dt %&#062;<BR><BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>*****************************<BR><BR >If you just chop off the "AM", that will work up to 12 hours. 24 hours if you format it for 24-hour time.<BR><BR>If you need more than that, you&#039;ll have to do the conversion by hand:<BR><BR>&#060;%<BR>hrs = numMinutes 60<BR>mins = numMinutes MOD 60<BR>Response.Write "Elapsed time: " & hrs & ":" & Right( "0" & mins, 2 ) & "&#060;P&#062;"<BR>%&#062;<BR><BR>No point in displaying seconds, given your question, since there will never be any.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
130

Thank you Bill. What if the number of minutes is like 2400? How would I include days in this?

4. Senior Member
Join Date
Dec 1969
Posts
96,118

If so, how many days per month? &#060;grin&#062;<BR><BR>Learn about the and MOD operators: <BR><BR> does *integer* division: 7 3 is 2, not 2.3333333, for example.<BR><BR>MOD gets the *remainder* after integer division is used: 7 MOD 3 is 1. Remember 3rd or 4th grade arithmetic, where you get an answer like "2 rem 1"? Well and MOD give you those two numbers.<BR><BR>So:<BR><BR>&#060;%<BR>numMins = ....<BR><BR>days = numMins (24 * 60)<BR>mins = numMins MOD (24 * 60)<BR>hrs = mins 60<BR>mins = mins MOD 60<BR><BR>Response.Write "Elapsed: " & days & " days, " & hrs & " hours, " & mins & " minutes"<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
130

Hey Bill, before you waste your time on that question about days. I found out that I don&#039;t need days, but I do need seconds. So, my question is, how do I get hh:mm:ss out of a difference of 2400 minutes? Or, would it be easier to do 64000 seconds?

6. Senior Member
Join Date
Dec 1969
Posts
130

Man, I&#039;m sorry. You&#039;re right..I need to learn more cuz I&#039;m new at this. But, of course, they ask me to do the difficult things first. I appreciate all your help.

7. Senior Member
Join Date
Dec 1969
Posts
96,118

Always 00 seconds...

...if the difference is in minutes, then the number of seconds is *always* 0, so simply tack on ":00" and be done.<BR><BR>Note that if you do DateDiff("n"...) you will *not* get fractional minutes.<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
130

RE: Always 00 seconds...

What if I do DateDiff("s"..)?

9. Senior Member
Join Date
Dec 1969
Posts
96,118

Then just extend the logic...

mins = differenceInSeconds 60<BR>secs = differenceInSeconds MOD 60<BR><BR>and work with minutes exactly as before.<BR><BR>

Posting Permissions

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