Hello
I am a newbie when it comes to date calcs in Lotusscript so please excuse me.
I have some code which is querying a door entry system. The idea is to send an email daily to show users entering the building before a certain time. My code has worked fine for several months, but daylight savings time has caused a fault.
My code uses timedifference to calculate whether a time is before 8:00am. However it calculates this using GMT instead of Localtime:
Set fst=New notesdatetime(first)
Set lst=New notesdatetime(last)
Set tempdtAM= New NotesDateTime("08:00 AM")
On Error Goto ohno
firstam&=fst.timedifference(tempdtAM)
lastam&=lst.timedifference(tempdtAM)
How do I ensure that this calculation is based on localtime?
Many thanks
Subject: New to Date calcs - DST and timedifference
Set fst=New notesdatetime(first)
Set lst=New notesdatetime(last)
Set tempdtAM= New NotesDateTime(“08:00 AM”)
On Error Goto ohno
fst.SetAnyDate
firstam&=fst.timedifference(tempdtAM)
lst.SetAnyDate
lastam&=lst.timedifference(tempdtAM)
If you remove the date you are also removing timezone information, so that the 8:00 AM time-only value can be compared to the value you read, on an equal footing. The hour in the fst & lst variables will remain at the hour of the source timezone. For instance, if first contained the string “4/03/2003 7:14 AM EDT”, then the timedifference will be -46 minutes, even if your server is not on Eastern Daylight time. If you need it otherwise, convert to your local timezone first before using SetAnyDate.
Sub Click(Source As Button)
Dim fo As New NotesDateTime("4/3/2003 7:14 AM EDT")
Dim ro As New NotesDateTime("8:00 AM")
fo.SetAnyDate
Print fo.timedifference(ro)/60.
End Sub
Subject: RE: New to Date calcs - DST and timedifference
Hi Andre
That worked a treat thanks - there’s no way I would have stumbled across that myself so thanks for saving me time.
Regards
Mark