To download NI software, including the products shown below, visit ni.com/downloads.
Overview
A number of useful date/time functions.
Description
Included is a small zip file which contains the following VIs:
DateTime - Formatted (Elapsed).vi
DateTime - Start Stop Time.vi
DateTime - Week Commencing.vi
Requirements
Software
Steps to Implement or Execute Code
1. Run the VI
Additional Information or Reference
The "DateTime - Formatted (Elapsed).vi" has two inputs, time A and time B, and returns time A formatted as a string, and the elapsed time between A and B formatted as a string. The elapsed time is recorded in the following format:
"x Day(s), x Hour(s), x Minute(s)" for times above 1 hour, for example, "3 Days, 1 Hour, 30 Minutes"
"x Minute(s), x Second(s)" for times below 1 hour
"x.x Seconds" for times below 45 seconds
"x.xx Seconds" for times below 5 seconds
"x millsecond(s)" for times below 1 second
The "DateTime - Start Stop Time.vi" is designed to be placed both before and after a block of code which requires timing. It can record the start time as a string and the stop time as a string complete with elapsed time (in days, hours, minutes, seconds, milliseconds).
The "DateTime - Week Commencing.vi" simply returns the date for the current week commencing on the day specified. For instance, it will return "Monday 2014-06-30" if the current date is 5th July 2014. The value returned may be used for creating folder names for test results which need to be stored in weekly collections.
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
I think your "DateTime - Formatted (Elapsed).vi" is overly complicated. You can just use "Format Into String.vi" with relative time formatting ("t" rather than "T" in the format string).
On the front panel, the "Formatted Time" indicator shows the formatted elapsed time with the largest time unit set to days, hours, minutes, and seconds. "Format Into String.vi" takes care of rolling time to the largest unit available in the format string.
The "Elapsed Time" control is just a numeric control with the format set to relative time. The control sends the number of seconds to the block diagram.
You can also set the "Elapsed Time" control to show larger units of time. I stopped at hours in the screenshots above to show that you can enter more than 24 hours.