Example Code

Convert hours to days, hours, minutes and seconds text string

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

Overview
This VI demonstrates how to convert hours in decimal format (fraction of hours) to a string containing days, hours, minutes and seconds with units.

 

Description
Here is a brief description of the example:

The example uses Quotient & Remainder function to extract days, hours, minutes and seconds from the Hours value. The values are converted to strings and their units appended.

E.g.: 1225.576 displays as "51 days, 1 hour, 34 minutes, 33 seconds"

The Hours input value is in decimal format, e.g. 1.5 equals 1 hour and 30 minutes. The result is output as a string and as a cluster. The vi is called from a parent vi. You can easily change the input from hours to seconds if need be as long as the unit of the values fed into the for loop is seconds

 

Requirements

  1. LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Load the vi
  2. Enter an hour value in Hours
  3. Run the vi and observe the output
  4. Call the vi from a parent vi

 

Additional Information or References

VI Snippet

Hours to Days and Time 2012 NIVerified.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.