Example Code

Date Time Functions (Elapsed, Week Commencing) Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

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

  • LabVIEW 2012 (or compatible)

 

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.

1-377 BD.jpg

 

Screen.png

 

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

Comments
David_Grucza
Member
Member
on

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

Format Elapsed Time.png

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.

Format Elapsed Time.jpg

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.

Numeric formatted as time.jpg

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.

Custom Numeric formatted as time.jpgCustom Format Elapsed Time.jpg 

David Grucza, CLD