WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: chrislegarth on November 28, 2018, 09:01:03 AM

Title: Daylight Savings Time
Post by: chrislegarth on November 28, 2018, 09:01:03 AM
I wrote a program that is use to check AD accounts of new hire employees to verify that the accounts is in an "OK" state whey they show up for orientation.
One of the checks is to determine if the original password has been changed.  What I am doing to verify this was to "hardcode" the date/time in the comments property of the AD account.  I would then compare that time (ESS Pwd. Set column) with the pwdlastset time (Pwd. Changed column).  If the times are off by more than a few seconds, I assume the password was changed from the original.  DST seems to had wrecked havoc on that comparison.  The script that creates accounts runs daily at 6:15AM local time (ET).  When comparing these times during DST, the comparison works.  Now that DST ended, the times are off by 1 hour.  Will the times be off again in March when the DST begins again?  What is the best way to accomplish what I am trying to do?  Should I store my "hardcoded" time as UTC and then calculate that against locate time?  See the screenshot to illustrate what is happening.

Any advice is appreciated and Thanks!

Why do we still change our clocks!?!?
Title: Re: Daylight Savings Time
Post by: ChuckC on November 28, 2018, 09:35:05 AM
Never store localized time stamp values.  Always store them as UTC/GMT values when you need to compare them again in the future.

As a work around, if you know the time zone and the time zone's DST rules for any given local time, could properly convert the localized time back to a UTC/GMT value.
Title: Re: Daylight Savings Time
Post by: td on November 28, 2018, 09:51:03 AM
I guess the first solution would be to have a password expiry policy so users are automagically forced to change them.  If that is not an option, you will need to convert either to or from UTC ( as Chuck indicated preferably too UTC.)  Assuming that you plan on are using WinBatch in some fashion to resolve the problem, there are several recent posts on this forum that have examples of doing exactly that. 

As to why Daylight Saving Time is still around I couldn't say.  Maybe it still exists to give contentious people another thing to debate about in their spare time.
Title: Re: Daylight Savings Time
Post by: chrislegarth on November 28, 2018, 12:24:56 PM
Thanks for the advice as always.  I have converted all my time stamps to UTC and convert them back to local time when comparing them.
All's good in my WinBatch world again.

We can thank New Zealand entomologist George Hudson and English builder and outdoorsman William Willett for proposing DST to the world!
Title: Re: Daylight Savings Time
Post by: snowsnowsnow on November 28, 2018, 03:10:51 PM
The really funny thing about DST is that most of the proposals I've seen for eliminating the clock changing ritual are in the form of "year around daylight saving time".  I.e., never standard time.

Which is obviously whack on its face...
Title: Re: Daylight Savings Time
Post by: Russell_Williams on November 29, 2018, 06:27:23 AM
When told the reason for Daylight Saving Time, the Old Indian said,
"Only the government would believe that you can cut a foot off the top
of a blanket, sew it to the bottom, and get a longer blanket."