06-27-2017 08:16 AM
Hello,
I'm a little confused by how doubles interact with time. I was just playing around and exploring and made the attached VI. I'm getting the current time then subtracting 0.5 as a double from it. I was expecting the result to be be the current time - 0.5 seconds or something similar, but it makes no sense to me. Can someone explain this?
Solved! Go to Solution.
06-27-2017 08:28 AM - edited 06-27-2017 08:31 AM
Hi Quark,
as I couldn't open your VI (stuck with LV2014 right now) I just made a small example of my own:
Timestamp minus 1.5 seconds…
Things might change once you set a unit for the DBL value: LabVIEW supports also time units (like s, min, h, d) and will calculate timestamps correctly, too!
06-27-2017 08:35 AM
@TheStrangeQuark wrote:
Hello,
I'm a little confused by how doubles interact with time. I was just playing around and exploring and made the attached VI. I'm getting the current time then subtracting 0.5 as a double from it. I was expecting the result to be be the current time - 0.5 seconds or something similar, but it makes no sense to me. Can someone explain this?
Actually, yes. Your 0.5 double has a unit of years. You can either change the units to seconds or just drop the unit part entirely.
06-27-2017 08:52 AM
@GerdW wrote:
Things might change once you set a unit for the DBL value: LabVIEW supports also time units (like s, min, h, d) and will calculate timestamps correctly, too!
That is what I just found in the VI. The constant had a unit of "a", which apparently is year. So 0.5 years (15.778938e6 seconds) was being subtracted. I recommend just deleting the constant, create a new one from the palettes, and wire that up to the subtraction. That new constant will not have units and make things work.
06-27-2017 08:55 AM
Good catch.
I could see something wasn't working right, but there was no indication that there were units hiding in there.
06-28-2017 11:00 AM
Another fun feature of time math, you can set the double (with no units) to be displayed in different formats. My favorite is the HH:MM:SS format. This makes the code more readable as here I am subtracting 1 hour 2 minutes and 3 seconds. If that was a normal double I would have to calculate the number of seconds in that time, but that isn't as easily documented as it is in this example.
This format change can be done by right clicking the constant and choosing Display Format >> Relative Time. This can also be done on double controls allowing for the user to enter time in this more intuitive format.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
06-28-2017 11:47 AM
I wish I could say that I was observant enough to notice that the two times were six months different, but I actually found out what was wrong by messing with the code and getting broken wires where there weren't supposed to be any.