LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timestamp difference

Solved!
Go to solution

Hi,

 

I'm doing a project where I record timestamps for each stage in a process. I'm recording the timestamp into a string txt file (Like below).

 

What is the best way to calculate the difference between two timestamps (that have already been converted to string).

Example Txt File.

50374211-1 15/07/2020 16:20:34 SS1A Liam Stage 1
50374211-1 15/07/2020 17:30:00 SS2A Liam Stage 2
50374211-1 15/07/2020 17:30:00 SS3A Liam Stage 3

 

So Ideally a calculation:  15/07/2020 17:30:00 - 15/07/2020 16:20:34 = Difference in seconds.

 

It's really the reconverting the timestamp from string back to a timestamp is the main problem.

 

Thanks,

Pád

 

 

0 Kudos
Message 1 of 8
(1,650 Views)

Hi Pad2,

 


@PadPad wrote:

What is the best way to calculate the difference between two timestamps (that have already been converted to string).

So Ideally a calculation:  15/07/2020 17:30:00 - 15/07/2020 16:20:34 = Difference in seconds.


Convert those strings back to timestamps, then just subtract them…

 


@PadPad wrote:

It's really the reconverting the timestamp from string back to a timestamp is the main problem.


Use ScanFromString with the correct format string!

I suggest "%<%d/%m/%y %H:%M:%S>T"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,648 Views)

To convert from string to timestamp, you just need a Scan From String node and the right format string to get back the timestamp in the correct format.

 

Then a Subtract node can take two timestamps as inputs and immediately returns a double of the seconds of difference between the two.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 3 of 8
(1,646 Views)

That's going to be ugly because if that's not UTC time, it's likely you'll have to contend with daylight saving issues.  If, let's say, you're burning in a unit over the weekend that you "spring forward", you'll have a "hole" in your data, .  It's even worse with "fall back" because data between 1am and 2am will be interleaved and/or overwritten.  Depending on whether your burn in was specified in hours or dates, you may come up an hour short or long.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 8
(1,632 Views)

I just thought I would mention that this is exactly why I always convert my timestamps to a double and save that number.

 

It's easy to reformat that double to any time/date format in Excel, and you can still do math on them after reformatting to find elapsed time.

 

TimeToOLE.png

 

About a decade or so ago an Engineer jumped down my throat for not being able to do math on a text timestamp.

========================
=== Engineer Ambiguously ===
========================
Message 5 of 8
(1,566 Views)

In the format string use %Y and not %y. %Y will return 2020 and %y will return 20 (the year without the century.

 

Ben64

0 Kudos
Message 6 of 8
(1,524 Views)
Solution
Accepted by PadPad

Cheers all for the help, I've used a bit of everything. For the GMT issue I've just recorded both GMT and UTC time stamps in the txt file and will use UTC for my time lapse calculations.

 

Here's my final code:

PadPad_0-1595254406613.png

 

Thanks,

Pád

0 Kudos
Message 7 of 8
(1,456 Views)

Hi Pad2,

 

you don't need to convert to DBL to subtract two timestamps.

What's the reason of that last Q&R function to calculate "Days"? Isn't "Days" already the IQ output of the "Hours" calculation?

 

Btw. using AutoCleanup would improve the code readability of the code shown in your image - usually this is a bad sign for your code quality…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(1,448 Views)