From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run a section of code a certain time of day

I have a problem which I am stuggeling to get right.

 

At a certain time of the day, the process must run a verification sequence which must be completed.

I was thinking about using two time values, the one being the actual time and the other being the target time. Once the actual time is equal or more than the target time, some code must run. This code must run (verification sequence) before any other code can run.

 

Please any advice would greatly be appreciated

0 Kudos
Message 1 of 8
(3,231 Views)

It will work.

And if you want you can keep this code in other loop so as your main code will also run in parallel with this conditional code.

Provided if you don't want other execution to stop when your conditional code is running.

 

Best of luck Smiley Wink

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 2 of 8
(3,228 Views)

Mainly what I want to know is how to compare the dates, set time and the actual time.

 

I am having trouble with this bit, the rest I would hopefully figure out

0 Kudos
Message 3 of 8
(3,216 Views)

You can compare dates using the numeric operators. Subtract The actual time from the set time. This will return the seconds difference.

 

If the result is < 0, then you can execute your conditional code. You can then add 1 day to your set time and continue comparing.

 

See Jim Kring's blog entry LabVIEW tip: easy relative timestamp calculations

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 4 of 8
(3,208 Views)

Hein,

 

This will be true when current time is equal or greater then the set time:

 

Compare time.png

 

 

 

Rgs,

 

Lucither

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 5 of 8
(3,207 Views)

@Lucither wrote:

Hein,

 

This will be true when current time is equal or greater then the set time:

 

Compare time.png

 

 

 

Rgs,

 

Lucither


The suggestion above are correct in answer the question "how to compare times?" but there is an ancillary question that goes with this challenge that being "What time value do I compare with the current time?"

 

Sounds simple at first glance and in most situations is a no-brainer UNLESS your app is a 24X7 365 day never go down app. In that case you have to deal with Daylight savings time (Lets ignore leap years seconds etc for now). With DST, we have to deal with the fact that there is one day with 23 hours and another day with 25 hours. One of those days does not have a "2 O-clock" times and the other has two, one with DST true and another with DST false. The other complication that coes with that fact is that (in the US at least) the dates on which those 23 and 25 hour days occur are defined by the whims of governement ("Those who seek to change times and way.." Is that reveleations?) so you can't code for changes ahead of time.

 

If you get past that challenge, the other thing to take note of is that Windows displays the creation date of files in the current time (DST T/F) so a file created at 1:00 last night may have a creation time of 2:00.

 

I hope you don't have to deal with DST and if you do, at least you have been warned.

 

Ben

 

Quoting from here...

 


This thing all things devours:
Birds, beasts, trees, flowers;
Gnaws iron, bites steel;
Grinds hard stones to meal;
Slays king, ruins town,
And beats high mountain down.

 

 


Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 8
(3,188 Views)
Thanks for all the advice, I can actually kick myself of how easy it really was. Luckily I do not have to worry about DST.
0 Kudos
Message 7 of 8
(3,129 Views)

 


@Ben wrote:

 Lucither wrote:

 

Compare time.png


The suggestion above are correct in answer the question "how to compare times?" but there is an ancillary question that goes with this challenge that being "What time value do I compare with the current time?"

 

Sounds simple at first glance and in most situations is a no-brainer UNLESS your app is a 24X7 365 day never go down app. In that case you have to deal with Daylight savings time (Lets ignore leap years seconds etc for now).

 

I hope you don't have to deal with DST and if you do, at least you have been warned.



 

One thing to note, the LabVIEW timestamp-data is DST unaware it is simply a time in UTC. The representation (a probe, an indicator, a control) is DST aware, you can however use UTC time. on the  representation.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 8 of 8
(3,120 Views)