How Do I Run a Piece of Code For a Specified Time Interval in LabVIEW?

Updated Dec 2, 2019

Reported In


  • LabVIEW

Issue Details

I need my program to be able to do a certain task for 10 minutes. Is there any way to do this in LabVIEW?


This is possible, using a combination of LabVIEW's built-in time functions and a Shift Register in a While Loop.
  1. Calculate the time period you want the code to run for, in seconds.
  2. Add this time period to the initial time as grabbed from Get Date/Time in Seconds.
  3. Initialize a Shift Register [right click on the edge of your While Loop to Add Shift Register] with the time you want the section to run until (the Goal Time).
  4. Compare the time from the Shift Register to see if Get Date/Time in Seconds (the Current Time) is past the time the code should run for by using a Greater Than comparator.
  5. Create a Case Structure around the section of code you want to run for the interval.
  6. Route the boolean output from this comparator into the selector on your Case Structure 
  7. In the False Case, place the code you want to run for 10 minutes. If the Current Time is not past the Goal Time, the code you want to run for 10 minutes will continue running. 
  8. In the True Case, you can enter a message or leave the case blank. If the Current Time is past the Goal Time, a message will appear that 10 minutes has passed, and the program will stop.

Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.