all groups > inetserver asp general > january 2005 >
You're in the

inetserver asp general

group:

DateAdd



DateAdd Wer
1/31/2005 6:17:44 AM
inetserver asp general: 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.
Re: DateAdd Bob Barrows [MVP]
1/31/2005 9:41:20 AM
[quoted text, click to view]
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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: DateAdd Ray Costanzo [MVP]
1/31/2005 9:49:09 AM
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

[quoted text, click to view]

Re: DateAdd Ray Costanzo [MVP]
1/31/2005 10:48:02 AM
My bad. :]

Ray at work

[quoted text, click to view]

Re: DateAdd Evertjan.
1/31/2005 3:04:45 PM
Wer wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:

[quoted text, click to view]

Could be don but I prefer the hands on way below.

[quoted text, click to view]

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



--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Re: DateAdd Evertjan.
1/31/2005 3:11:05 PM
Ray Costanzo [MVP] wrote on 31 jan 2005 in
microsoft.public.inetserver.asp.general:
[quoted text, click to view]

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

They are just amounts of time to be added.


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
AddThis Social Bookmark Button