LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with time calculations

Solved!
Go to solution

I've tried numerous searches but can't seem to find what I need to do. I need to read a file with two columns, the first column is the time of an event. I then need to calculate the time between each event (row). I know I need to use a for loop to read through the file but I cannot find any information on what the best way to calculate the time between each event so that I can get stastics like average time per cycle, time since last cycle etc.The only way I can think of is to read the file as a string and then parse the time but that doesn't seem like an efficient way of doing things.

 

example: data.csv

8:00         10

8:12         8

10:00       2

11:12       3

0 Kudos
Message 1 of 9
(3,274 Views)

Hi icemaker,

 

when the time is saved as HH:MM you have to convert this string to a number before oyu can do any calclulations with it.

You may try ScanFromString with a format string of "%<%H:%M>T" for the beginning...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(3,252 Views)

Gerd,

Thanks for the reply. I get what you mean by converting from string to numbers, makes sense. I tried your scan from string and I get a -32400 like number for the time in a double indicator. Is it incorrect or am I doing something wrong?

0 Kudos
Message 3 of 9
(3,230 Views)
Solution
Accepted by topic author icemaker

Use "%<%H:%M>t" as the format string instead. The capital T formats the time as an absolute time, which based on your format isn't what you're working with. The lowercase t will format it as a relative time stamp and you should be able to calculate your time between events.

 

Hope this helps,

 

Rob

0 Kudos
Message 4 of 9
(3,218 Views)

I see the difference in time with the smaller t. Really my question is more of what exactly do I do with that number it pumps out? How do I subtract one reading from another to see the time between? Thanks for the help so far it has been great.

0 Kudos
Message 5 of 9
(3,201 Views)

On the numeric palette is the subtract function. That works quite well in subtracting one value from another.Smiley Wink

 

Message 6 of 9
(3,172 Views)

Note that converted times are in seconds.  Absolute times are seconds from midnight Jan 1, 1904.

0 Kudos
Message 7 of 9
(3,152 Views)

Where is my staples easy button? I guess that was an obvious one I should have tried. Thanks again gentlemen you have been a big help.

0 Kudos
Message 8 of 9
(3,134 Views)

easy button big Pictures, Images and Photos

Couldn't resist...

Message 9 of 9
(3,088 Views)