Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Simple (I thought) time comparison?by haukex (Archbishop) |
on Dec 20, 2016 at 14:08 UTC ( [id://1178209]=note: print w/replies, xml ) | Need Help?? |
Hi sjessie, As hippo and davido have already identified, the issue is with time zones. Personally, I like to use the DateTime module since it includes a lot of functionality, including time zones. (Because of that it's a little more heavyweight, but that should only be noticeable if your script does a lot of date/time calculations, so personally I just throw all of my date/time stuff at the DateTime suite because it can handle it all, and only consider using other modules as an optimization if necessary.) Anyway, here are two methods that work. Note that this handles time zones properly, for example try changing the first "America/New_York" to "America/Chicago". Update: Just to emphasize this, the key is that all the DateTime objects involved in the calculations and comparisons need to have their time zones set properly.
Hope this helps,
In Section
Seekers of Perl Wisdom
|
|