LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time/Date string to seconds?

I have data that contains a time/date string (from Format Date/Time String) I saved to a .txt file. I would now like to be able to take that data and make calculations on it (ex. time between two points). Is it possible to do this?

Thanks,
Patrick
0 Kudos
Message 1 of 14
(7,710 Views)
In the Time & Dialog palette there is a function called "Date/Time to Seconds". You feed it a cluster containing the day, month, year, hour, min, sec, etc...

You can get most of the values for the cluster by parsing the date and time string that was formatted by the Format Date/Time String function. I would recommend using a Scan from String function to parse the string and extract the necessary values.

The output of the Date/Time to Seconds function is a U32. Run both strings through and you've got two time points in seconds. Subtract for the difference between the two points.

Daniel L. Press
NI Certified LabVIEW Developer
PrimeTest Corporation
www.primetest.com
Message 2 of 14
(7,710 Views)
Just use the function Date/Time to Seconds. It's in the Time & Dialog palette below and to the left of the Format Date/Time String function. You'll need to parse out the string, convert to integers, and wire the results to the input cluster.
0 Kudos
Message 3 of 14
(7,710 Views)

Given:  date/time string:  11/20/2019 11:59:31 AM

Another way is to convert the date/time string back to a Time Stamp cluster.

Then you can do any math you need very easily.

 

An easy way to get back to Time Stamp format is to use Scan From String function with %T for the format string input.  You will see the output 1  for this function change to a Time Stamp cluster.

 

If you are concatenating a date string with a time string, you must add the date string to the time string (in other words the upper input to the concat function has to be the TIME string, the lower input has to be the DATE string.

Certified LabVIEW Developer
LabVIEW 7.1 - Present
Message 4 of 14
(6,358 Views)

If you convert a time stamp to a double you can do all the math you want on it and convert it back.

 

seconds2.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 14
(6,355 Views)

@RTSLVU wrote:

If you convert a time stamp to a double you can do all the math you want on it and convert it back.

 

seconds2.png


No need for the Timestamp to Double and vv. at all. The arithmetic plus and minus nodes will operate correctly when you try to add or subtract a double (or integer) from a timestamp.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 14
(6,323 Views)

@rolfk wrote:

@RTSLVU wrote:

If you convert a time stamp to a double you can do all the math you want on it and convert it back.

 

seconds2.png


No need for the Timestamp to Double and vv. at all. The arithmetic plus and minus nodes will operate correctly when you try to add or subtract a double (or integer) from a timestamp.


Right... But I really detest coercion dots

 

AKA "Loser Dots" 😛 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 14
(6,316 Views)

Not quite sure where you see coercion dots. This is LabVIEW 2016, but I doubt there is much difference since at least around 8.2. Even then a coercion dot is usually not really anything else than an implicit conversion functions. If you have coercion dots on scalar wires and get rid of them by adding a conversion node, you have basically not gained anything nore lost anything. Of course if you can get rid of coercion dots altogether by changing dataypes consistently throughout a diagram, that is even better. If conversions are unavoidable it is a good idea to do them explicitedly on the scalar wire inside a loop rather than on the array that goes into or out of an autoindexed loop, though.

 

Timestamp Arithmetic.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 14
(6,312 Views)

Hi, 

 

additionally you can enable the unit of the numeric constant and set it to "4h" instead of plain "14400" (seconds)...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 14
(6,307 Views)

Since you have saved the data to a text file, I assume you are then reading that file and want to convert that time stamp back to a LabVIEW data type. Try something like this...

 

image.png

 

The trick is getting the format string to match the format you have save the data as.

After that, as other have pointed out, just simply add or subtract as required.

 

EDIT: Oops, looks like GPeople beat me too it

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 10 of 14
(6,296 Views)