[AccessD] Time Comparisons

Gustav Brock Gustav at cactus.dk
Fri Sep 12 11:39:50 CDT 2008


Hi Tony

Yes, DateDiff ignores (rounds) fractional seconds.
You can read the 5 from a variable if it is to change during your loop.

/gustav

>>> iggy at nanaimo.ark.com 11-09-2008 18:22:00 >>>
Hey Gustav
Sorry for not replying quicker, I was trying your example. My time 
intervals change as the code loops through a table of activities.
Question - your method avoids the second fracture problems with time? 
That is why I was using > rather than =.

Gustav Brock wrote:

>Hi Tony
>
>You could skip all the string handling and use a static variable.
>
>Private Sub Form_Timer()
>
>  Static datLast As Date
>  Dim datNow As Date
>
>  datNow = Now
>  If DateDiff("s", datLast, datNow) > 5 Then
>    ' Do something.
>    Me!BTime.Value = datNow
>    datLast = datNow
>  End If
>
>End Sub
>
>Set the format property of BTime to short time.
>
>/gustav
>
>  
>
>>>>iggy at nanaimo.ark.com 11-09-2008 16:44:53 >>>
>>>>        
>>>>
>Hey All
>I am trying to trigger an event when the current time = the calculated 
>time. I have been fiddling with this, as previous versions would trip up 
>every so often (ie. after 28 hours). The current version has been 
>running for 3 days and everything seems to be working fine, just wanted 
>to check with the time experts if I am doing this correctly.
>
>Me!BTime - unbound on form
>Timer = 1000
>
>Private Sub Form_Open(Cancel As Integer)
>Me!Btime = cstr(Format(TimeSerial(Hour(Now()), Minute(Now()), 
>Second(Now()) + 5), "long time"))
>End Sub
>
>Private Sub Form_Timer()
>        If cstr(Format(TimeSerial(Hour(Now()), Minute(Now()), 
>Second(Now())), "long time"))>
>    cstr(Format(TimeSerial(Hour(me!BTime), Minute(me!BTime), 
>Second(Me!Btime)), "long time"))
>       Then
>            Me!BTime = cstr(Format(TimeSerial(Hour(Now()), 
>Minute(Now()), Second(Now()) + 5), "long time"))
>        End If
>
>End Sub






More information about the AccessD mailing list