07-17-2020 06:44 AM
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
Solved! Go to Solution.
07-17-2020 06:49 AM
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"…
07-17-2020 06:54 AM
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.
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.
07-17-2020 07:18 AM
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.
07-17-2020 05:20 PM - edited 07-17-2020 05:24 PM
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.
About a decade or so ago an Engineer jumped down my throat for not being able to do math on a text timestamp.
07-18-2020 06:33 AM
07-20-2020 09:14 AM
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:
Thanks,
Pád
07-20-2020 09:25 AM - edited 07-20-2020 09:26 AM
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…