PDA

View Full Version : Solved: Difference between two times - Macro



Sathisc
02-25-2010, 06:45 AM
I created an user form where I have two textboxes 1 & 2. I want to find the difference between two times in the 3 box.

Can anyone help me with the code?


Cheers,
:think: :think:
Sathish

krishhi
02-25-2010, 08:49 AM
what do you want.?
Is that userform text boxes has already data or the user has to input the data?

Sathisc
02-25-2010, 09:01 AM
Textbox1.value = now
Textbox2.value = now
i want to know the difference between two times
(Textbox2.value - Textbox1.value)

kindly let me know to find the diff between two times.

krishhi
02-25-2010, 09:18 PM
if the textbox1 & textbox2 values has NOW then the answer will be the "0".
can you give more specific what you actually require and how it will be use for you?

mbarron
02-25-2010, 10:16 PM
If you subtract the two values, you will have the time difference expressed in days. Whole numbers are the days while the decimal portion of the number is the part of a day. For example 1.625825 would be 1 day and 0.625 of a day which would break down to 15 hours - 1 minute - and 11 seconds.

To display the difference, Try something like:
Dim diff As Double
diff = CDate(TextBox2.Value) - CDate(TextBox1.Value)
MsgBox Int(diff) & " days(s) " & Format(diff, "h") & " hours " _
& Format(diff, "n") & " minutes " & Format(diff, "s") & " seconds"