From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I subtract timestamps to give me a DBL time in seconds?

Dear Community,

I would like to compute the number of seconds (as a DBL, such as 6.571743e32 sec) that have elapsed between one 128-bit timestamp and another. What is the fastest way to do that?

Thanks!
Cas
0 Kudos
Message 1 of 27
(9,541 Views)
Do you mean like this?

Les Hammer
Message 2 of 27
(9,542 Views)
Les, your attachment crashes LabVIEW 7.0 and 7.1 if I try to open it. Is it just me?
0 Kudos
Message 3 of 27
(9,542 Views)
Hmm, must have gotten corrupted in attachement.
I'll try again.

I found that if I take one "Get Date/Time In Seconds" and subtract it from another it automatically gives a DBL.

Les
0 Kudos
Message 4 of 27
(9,542 Views)
You can also explicitly convert at any time by just using the To Double Precision Float function from the Numeric Conversion pallete. This will give you the number of seconds (including fractional seconds) since July 1904 (so you usually just end up subtracting it anyhow).

Regards,
Ryan K.
0 Kudos
Message 5 of 27
(9,542 Views)
True - in fact that would get rid of those conversion dots on the subtract widget of my program. 🙂

Les
0 Kudos
Message 6 of 27
(9,542 Views)

@LesHammer wrote:
True - in fact that would get rid of those conversion dots on the subtract widget of my program. 🙂

No. Do not add coercion bullets. The coercion that the Subtract node is doing is not a coercion to double. It's an under-the-hood conversion that shouldn't, in my opinion, be reflected on the block diagram. If you coerce to double first, you will get the wrong answer. Coercing to double gets you a timestamp that is almost right, but not quite. You will be off by fractions of a second. It's small, but some users care about very small amounts.

 

These two outputs are NOT the same.

AristosQueue_0-1650327921231.png

AristosQueue_1-1650327950942.png

 

 

 

Message 7 of 27
(3,040 Views)

@AristosQueue (NI) wrote:

@LesHammer wrote:
True - in fact that would get rid of those conversion dots on the subtract widget of my program. 🙂

No. Do not add coercion bullets. The coercion that the Subtract node is doing is not a coercion to double. It's an under-the-hood conversion that shouldn't, in my opinion, be reflected on the block diagram. If you coerce to double first, you will get the wrong answer. Coercing to double gets you a timestamp that is almost right, but not quite. You will be off by fractions of a second. It's small, but some users care about very small amounts.

 

These two outputs are NOT the same.

AristosQueue_0-1650327921231.png

AristosQueue_1-1650327950942.png

 

 

 


What prompted you to post to an 18 year old topic?  😄  I mean, this is good info, but...?

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 8 of 27
(3,011 Views)

@billko wrote:


What prompted you to post to an 18 year old topic?  😄  I mean, this is good info, but...?


If I would have a guess, he was working on something in LabVIEW and searching the forum for related posts and stumbling across this. And found this important enough to mention. Also I would agree with his assessment that this should actually not cause red coercion dots to appear.

 

Yes this function has to do a conversion eventually as is shown by the different output result type of it but no it is not a coercion really. It does not force the inputs to double to do its conversion but rather calculate the fractional and integer part of the timestamp difference separately and then combines them to the actual result which happens to be a double. The important bit is that the conversion to the double happens after the arithmetic operation NOT before, so the full precision of the double numeric space can be used.

 

And this definitely can matter. The timestamp only uses 32-bit of the fractional 64-bit currently (well last I checked which is a few years and that still is less than a ns resolution (1/2^32)) and to represent the current date it also requires 32-bit of the integer part and that will be 33-bit somewhere around 2037.

 

A double only has 52-bit of mantissa bits and 64 bits in total so if you do a conversion before the arithmetic operation the fractional bits are immediately reduced to about 20 bits of the 32 possible bits which is only about 1us resolution anymore and then the subtraction is performed. If the subtraction is done in integer space and then converted and the difference is small the result is then accurate to the full 32-bit that the fractional part of the timestamp offers.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 27
(3,007 Views)

@billko wrote:
What prompted you to post to an 18 year old topic?  😄  I mean, this is good info, but...?

Someone was using coercion bullets in their diagram and cited this as their reasoning. It's still the number one hit on Google for info on the topic. 🙂

 

Message 10 of 27
(2,984 Views)