Hello,
I am struggling with date/time calculation in VBA.
1. Can I add/subtract dates as in the next example:
Dim vStart As Date, vEnd As Date, vHours As Date
dim vHours1 as integer
vStart="20:00"
vEnd = "23:00"
vHours=vEnd-vStart
vHours gives me "03:00:00" which is correct to me. Is is simple to use, write and understand.
So why should I use vHours1 = DateDiff("n", vStart, vEnd)?
vHours1=180 (minutes) which also correct
2.
Dim vStart As Date, vEnd As Date, vHours As Date
dim vHours1 as integer
dim var1 as double, var2 as double, var3 as double
vStart="01:00"
vEnd="01:00"
vHours=vStart-vEnd
var1 = vstart
var2=vend
var3=var2-var1
vHours gives me "00:00"
in fact it is not (sometimes, not all the time !!!!)
var1=4,1666667E-02
var2=4,1666667E-02
var3=2,081668171E-17 (sometimes var3=0 !!)
So var1 <> var2 and so vStart<>vEnd !!!!!
This means that if I compare vStart and vEnd as in
if vStart=Vend then ......
sometimes they are equal and sometimes they are not
Question is :
How should I should compare times
if vStart=Vend then ......
if vStart>Vend then ......
etc.
Thanks for your help.
I am struggling with date/time calculation in VBA.
1. Can I add/subtract dates as in the next example:
Dim vStart As Date, vEnd As Date, vHours As Date
dim vHours1 as integer
vStart="20:00"
vEnd = "23:00"
vHours=vEnd-vStart
vHours gives me "03:00:00" which is correct to me. Is is simple to use, write and understand.
So why should I use vHours1 = DateDiff("n", vStart, vEnd)?
vHours1=180 (minutes) which also correct
2.
Dim vStart As Date, vEnd As Date, vHours As Date
dim vHours1 as integer
dim var1 as double, var2 as double, var3 as double
vStart="01:00"
vEnd="01:00"
vHours=vStart-vEnd
var1 = vstart
var2=vend
var3=var2-var1
vHours gives me "00:00"
in fact it is not (sometimes, not all the time !!!!)
var1=4,1666667E-02
var2=4,1666667E-02
var3=2,081668171E-17 (sometimes var3=0 !!)
So var1 <> var2 and so vStart<>vEnd !!!!!
This means that if I compare vStart and vEnd as in
if vStart=Vend then ......
sometimes they are equal and sometimes they are not
Question is :
How should I should compare times
if vStart=Vend then ......
if vStart>Vend then ......
etc.
Thanks for your help.