calculate difference between two times? (1 Viewer)

zambam

Registered User.
Local time
Yesterday, 17:57
Joined
Mar 19, 2006
Messages
39
i have two text boxes, and want to calculate the difference in time between them.
how do i do this? the date diff function is for dates but what is the function for time?

thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:57
Joined
Aug 30, 2003
Messages
36,123
The DateDiff function can also calculate time, or you can simply subtract the 2.
 

zambam

Registered User.
Local time
Yesterday, 17:57
Joined
Mar 19, 2006
Messages
39
thanks but how?

this is my code so far:

dim time1 as string
dim time2 as string

time1 = text1
time2 = text2

text3 = datediff (text1-text2)

but it doesnt work, and highlights the 'datediff' part saying argument not optional!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:57
Joined
Aug 30, 2003
Messages
36,123
First of all, why would you use strings for date/time values? Second, the DateDiff function has 3 required arguments. More info in Help.
 

zambam

Registered User.
Local time
Yesterday, 17:57
Joined
Mar 19, 2006
Messages
39
because the values of text 1 and 2 are determined by the actual time. when a button is clicked, the time is inserted into the textboxes, therefore making it a variable.

btw, what is the best datatype to give the time?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:57
Joined
Aug 30, 2003
Messages
36,123
But you should declare the variables as dates rather than strings, since that's what they are. In this case it will probably still work, as I think the DateDiff will convert them, but it would be better to properly declare them IMHO.

Secondly, you declare and set the 2 variables, but you don't actually use them in the DateDiff.
 

XerxesDGreat

New member
Local time
Yesterday, 17:57
Joined
Feb 28, 2007
Messages
4
Use either the "Date" or the "Time" datatype, depending on what you're looking for, to record the time. If you're only concerned with days, "Date" is better. Likewise, if you're after hours, minutes, and seconds, use "Time" (although, unless I'm mistaken, time will store the date as well).

Datediff uses 3 parameters: a string telling you what type of interval you want (i.e. yyyy for year to four places, q for quarter, h for hours, etc.); date 1; and date 2. You can do a web search for more info on how to use it.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:57
Joined
Aug 30, 2003
Messages
36,123
Use either the "Date" or the "Time" datatype, depending on what you're looking for, to record the time. If you're only concerned with days, "Date" is better. Likewise, if you're after hours, minutes, and seconds, use "Time" (although, unless I'm mistaken, time will store the date as well).

Is there a new Time data type in 2007? Because there is not in previous versions.
 

XerxesDGreat

New member
Local time
Yesterday, 17:57
Joined
Feb 28, 2007
Messages
4
(looks for "oops, I'm embarrassed" smiley...)

I don't know about 2007, but mine doesn't. Perhaps doing my homework a bit more before posting would be a good thing...

I was right about the rest of it, tho! ;)
 

Users who are viewing this thread

Top Bottom