Example Code

Calculating the Difference Between Time Strings (LV)

Code and Documents

Attachment

This VI finds the difference in seconds of two date/time strings. First the VI parses and converts each of the two time strings into an array of numbers. Then the VI converts and maps these numbers to the cluster input for the Date/Time to Seconds VI to find the number of seconds elapsed since January 1, 1904. Then the VI subtracts the two times.

The times are date/time strings in the form of
"Month/Day/YearHour:Minutes:Seconds" or
"Month-Day-YearHour:Minutes:Seconds"

Valid times are between 12:00:00 AM to 11:59:59 AM and 12:00:00 PM to 11:59:59 PM. If AM or PM is not included a 24 hour clock is assumed (00:00:00 to 23:59:59).

The year can be in 2-digit or 4-digit format. The VI assumes the 2-digit format to be 20xx.

If either of the time strings are not in the correct format, then the result from Date/Time to Seconds VI is zero and the result is invalid.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors