DateAdd

W

Wer

Hi,

I'm trying to add hours together in the format HH:MM + HH:MM. There
doesn't seem to be a functional part of DateAdd that will accomplish
this though ?

The calculation is to work out how many hours have been spent on a
website so exceeding the 24:00 is fine.
Is there another function that would accomplish this ?

Thanks

W.
 
B

Bob Barrows [MVP]

Wer said:
Hi,

I'm trying to add hours together in the format HH:MM + HH:MM. There
doesn't seem to be a functional part of DateAdd that will accomplish
this though ?

The calculation is to work out how many hours have been spent on a
website so exceeding the 24:00 is fine.
Is there another function that would accomplish this ?

Thanks

W.
Use DATEPART to convert the datetime values to the appropriate resolution
and simply add them together arithmetically. You will need to create a
function to display the results in hh:mm format if that is required, because
that ability is not builtin. Google should provide many examples of doing
this. I would search for

vbscript format time duration hh:mm

Bob Barrows
 
R

Ray Costanzo [MVP]

How would it know if you go from 13:50 to 14:50 that you mean 1 hour, 25
hours, 49 hours, etc.? You have to include a date to avoid this ambiguity.

Ray at work
 
E

Evertjan.

Wer wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
I'm trying to add hours together in the format HH:MM + HH:MM. There
doesn't seem to be a functional part of DateAdd that will accomplish
this though ?

Could be don but I prefer the hands on way below.
The calculation is to work out how many hours have been spent on a
website so exceeding the 24:00 is fine.
Is there another function that would accomplish this ?

Using vbscript:

time1 = "13:17"
time2 = "12:51"

time1a = split(time1,":")
time2a = split(time2,":")

mi = 1*time1a(1) + 1*time2a(1)
hr = 1*time1a(0) + 1*time2a(0)

if mi>59 then mi = mi-60 : hr = hr+1

response.write hr & ":" & two(mi) ' writes 26:08

function two(x)
if x<10 then x = "0" & x
two = x
end function
 
E

Evertjan.

Ray Costanzo [MVP] wrote on 31 jan 2005 in
microsoft.public.inetserver.asp.general:
How would it know if you go from 13:50 to 14:50 that you mean 1 hour,
25 hours, 49 hours, etc.? You have to include a date to avoid this
ambiguity.

Not the difference, Ray, but the sum was asked for.

They are just amounts of time to be added.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top