LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the date for the previous day

How do I get the previous day's date with LabView 7.0? Is there a built in function that will allow me to do this (taking into account the number of days in a month, leap years etc) or do I have to write my own vi?
Thank you,
KB
0 Kudos
Message 1 of 16
(7,048 Views)
Just subtract 86400 seconds from the current time.
(See attached - or substitute whatever format item you like.)

Les.Hammer@CompleteTest.com
Message 2 of 16
(7,048 Views)
All you have to do is use the Get Date/Time in Seconds and then subtract the number of seconds in a day. The result is a time stamp that should account for everything.
Message 3 of 16
(7,048 Views)
Thanks. That worked. I went along a similar path, except I tried to subtract 1 day from the day of year and it was not working as well. Once again, thanks.
0 Kudos
Message 4 of 16
(7,048 Views)

Try this close to midnight on the day after the switch to DST -- you will get the wrong day.

0 Kudos
Message 5 of 16
(5,481 Views)

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

Message 6 of 16
(5,457 Views)

@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 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 16
(5,430 Views)

@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 

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

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.

0 Kudos
Message 9 of 16
(5,416 Views)

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

 

0 Kudos
Message 10 of 16
(5,412 Views)