08-09-2004 02:32 PM
08-09-2004 03:15 PM
08-09-2004 03:21 PM
08-09-2004 03:46 PM
07-31-2019 11:13 AM
Try this close to midnight on the day after the switch to DST -- you will get the wrong day.
07-31-2019 12:17 PM
@balatim wrote:
Try this close to midnight on the day after the switch to DST -- you will get the wrong day.
I'm not sure why you're responding to this 15 year old thread, but can you please explain how this will not work on the day after the switch to DST? Since DST doesn't happen at midnight this should not be an issue.
07-31-2019 03:03 PM
@balatim wrote:
Try this close to midnight on the day after the switch to DST -- you will get the wrong day.
Why? I believe that such a day has 82,800 seconds. Did you assume a constant 86,400? That assumption is demonstrably incorrect
07-31-2019 03:09 PM
@balatim wrote:
Try this close to midnight on the day after the switch to DST -- you will get the wrong day.
Yes you are correct.
Time is a funny thing (see here) when trying to get the same time tomorrow or yesterday.
The add/subtract a days worth of seconds work most of the time but near 2:00 AM on two days of the year it will fail.
In one case you will end up on the same day because that day has 25 hours and the other day you can miss a day completely because it only has 23 hours.
Make it more complicated is when that happens is determined by the government and few good things come out of government (stay on topic Ben!).
Something that does work is "Second to Date/Time" in a loop subtracting off or adding to the time with 1 second and then testing if the data changed. That VI uses the OS to convert the time and figure out how the time should be converted. The OS should get patched when the laws change (again!).
Ben
07-31-2019 03:21 PM
Would it still not correctly get the date for yesterday? I realize that the time would be incorrect, but the date should be correct. When DST begins if we subtract the hours from 2:00 AM will that not give 1:00 AM yesterday? When DST ends when we subtract the hours will it not give 2:00 AM yesterday? I am truly curious as I would have expected this to be correct.
07-31-2019 03:27 PM
@Ben wrote:
The add/subtract a days worth of seconds work most of the time but near 2:00 AM on two days of the year it will fail.
Ben
Really more like the hour before or after midnight on the days next to the time change..
Spring forward. The day prior to the time change date, between 11pm-midnight, adding 24 hours (86,400 seconds) will skip over the day that the the time changes, and into the day after that. You'll effectively added 2 days. (11:30pm +24 hours will become 12:30 am 2 days later.) Likewise for the day after the time change between midnight-1am and subtracting 24 hours leaves you on the same date.
Fall back. Between 11pm-midnight on the date that the time changed, you subtract 24 hours, you are still in the same day. So 11:30pm -24 hours becomes 12:30am of the same date. Likewise the day of the time change between midnight and 1am and adding 24 hours leaves you on the same data.
I feel like I was looking at or participating in a thread in the not too distant past with this same discussion. If I can find it again, I'll post a link to it.
I think if you used the time record functions and take the current time, arbitrarily coerce the hour to noon and convert back to a timestamp and do the addition and subtraction, you won't have an issue.