get the function to add time
Printable View
get the function to add time
How about DateDiff()?
we have to ADD hrs and minutes.
for an example ...
01:30 and 02:30 should give us 4 hrs as answer.
DateAdd
its not working..
i have tried it
i have given as
dateadd("h","01:30","2:30") it gives me error as typemismatch
and for
dateadd("h","01.30","2:30") it gives me result as "02:30"
That's the same code, how can it give you both a type mismatch error and a result?
You need to pass it date variables, not strings.
It is not the same code.
In the first sample, the second argument is a time value. In the second sample it is a decimal value (which is correct).
Even though the second argument is defined as a double, you cannot add decimal portions (ie 1.5 hours). VB rounds the value to the nearest integer.
So to add 1.5 hours, use minutes instead
DateAdd("n", 90, "2:30")
try datediff insteadbut if you time is in hours minutes you will have to get the difference in minutse and then calculte it to hours and minutesVB Code:
x = DateDiff("h", "01:30", "2:30") ' returns 1VB Code:
Dim t As Date x = DateDiff("n", "01:30", "2:35") ' returns 65 t = x \ 60 & ":" & x Mod 60