LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the date for the previous day


@RavensFan wrote:

@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.

 


Ah, I see. Thanks for the explanation.

0 Kudos
Message 11 of 16
(986 Views)

@RavensFan wrote:

@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.

 


Regarding the time thread, wasn't that the one about "what date is it if i add 2 million seconds?"

In many countries the time change is around 2AM (here it's from 2->3 in spring and 3->2 in fall), which makes the error change rather small. I'd just say "we know it can happen if anyone works at 2AM on equinox".

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 12 of 16
(961 Views)

@Yamaeda wrote:

@RavensFan wrote:

@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.

 


Regarding the time thread, wasn't that the one about "what date is it if i add 2 million seconds?"

In many countries the time change is around 2AM (here it's from 2->3 in spring and 3->2 in fall), which makes the error change rather small. I'd just say "we know it can happen if anyone works at 2AM on equinox".

/Y


And, Of course this never happens if you report time in UTC,

Better yet, A TAI Time Format Specifier would really be beneficial by making "Time" absolutely contiguous. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 13 of 16
(953 Views)

.... I'd just say "we know it can happen if anyone works at 2AM on equinox".

/Y


That is a luxury that I did not have when I ran into it face first.

 

I was developing an application where the user could configure what time of the day the log files would be closed and new ones opened. Worked great until the time changed.

 

And then there was the issue of the time stamps on the files...

 

Windows formats the time based on the current Time zone DST setting.

 

When the DST setting changed it made it look like my log files were off by an hour.

 

I tagged this post by Rolf with time related info so it may help out.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 14 of 16
(948 Views)

My final solution looks like this:

Same time previous daySame time previous day

'Luckily' LabView doesn't account for leap seconds, so we don't need to take that into account.

Message 15 of 16
(943 Views)

@balatim wrote:

My final solution looks like this:

Same time previous daySame time previous day

'Luckily' LabView doesn't account for leap seconds, so we don't need to take that into account.


Not yet- its a darned good excuse to Kudos the idea for a TAI format specifier in my earlier post though 😉


"Should be" isn't "Is" -Jay
0 Kudos
Message 16 of 16
(924 Views)