Example Code

Convert String to TimeStamp and Calculate time difference with current Time

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 example converts a string in HH:MM:SS+UTC HH:MM format into a Time Stamp and outputs the difference with the current time in seconds.

 

 

Description:

The string is converted into a Time Stamp by using the Scan from String function. A format string specific to Time Stamps is used to make sure the string is properly converted into a Time Stamp. This format string can be found in the LabVIEW Help File for Scan from String. The date portion of the time stamp is extracted from the Get Date/Time in Seconds function.

 

 

Requirements:

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code:

  1. Download the attcahed Zip folder.
  2. Open the "String to TimeStamp Conversion.vi"
  3. Enter the Time in the String Control in the format HH:MM:SS+HH:MM or HH:MM:SS-HH:MM to specify the time zone difference referenced to UTC in  hours and minutes where the UTC time in HH:MM format is after the sign
  4. Run the VI

 

Additional Information or References:


Block Diagram

BD.PNG

 

 

Front Panel:

FP.PNG

 

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com

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

Comments
Todd S.
NI Employee (retired)
on

This will come in handy, thanks for saving me the time! Get it?

Todd S.
LabVIEW Community Manager
National Instruments
Erik_J
NI Employee (retired)
on

Hahaha!  Saved me time too.  Thanks!

Erik Månsson
Member
Member
on

I try to parse a string that contains a timezone in the format "%Y-%m-%dT%H:%M:%S_%z". Thus "2009-10-16T13:00:00_01:00:00" has the suffix for a UTC+1h timezone and represents 2009-10-16T12:00:00 in UTC.

But the Scan From String Function does not seem to care about the %z-value. If it is missing it gives no error and if it is present the timezone value does not affect the timestamp value (neither before or after conversion to double).

Is there any way to make LabVIEW 8.6 scan the timezone? I will try a manual workaround that parses the timezone separately.

erchaj
Member
Member
on

Thanks.

海侠
Member
Member
on

Thank you!

buton
Member
Member
on

thanks.. just what i was looking for..

CLAD, CTD
NIST_Vance
Member
Member
on

There is an error in the example.  If you are using a four digit year the format code must be upper case Y; %y should be %Y.  Works very well.  Thanks.