LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time Calculations

Solved!
Go to solution

Hi,

   I am trying to create a vi that calculates the difference between two times (as generated by the Get Sate / Time String function).

Essentially my vi needs 5 inputs:

Start Time; Start Date; End Time; End Date; Want Seconds? (F).

It also needs 1 output:

Elapsed Time (String "YYYY/MM/DD|HH:MM:SS")

 

To do something like this I would need to program a calendar into a vi. This would be extremely time consuming and I was wondering if there was anything already out there that anyone knew of that could make my life a little simpler!?

 

Many thanks, Alec

0 Kudos
Message 1 of 13
(3,769 Views)

Why would you need to program a calendar?

 

Maybe I didn't undestand what you want...  I'll do a quick example of what I understood and you can comment on how far I was from the target...

 

R

Message 2 of 13
(3,757 Views)
subtracting (polymorphic function) two time types yields a double precision number which is the difference between the two times in seconds.  This should simplify calculations.
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 3 of 13
(3,750 Views)

Agreed Paul,

 

But what if the elapsed time goes beyond 1 month and you want to show the elapsed time as YYYY/MM/DD HH:MM:SS ?

Which actually does not make sense...  because you would never represent delta time by a datestamp.

 

Is it okay to simply display delta time as:

(delta) days

(delta) hours

(delta) minutes

(delta) seconds

?

 

For the obvious reason that different months have different number of days and a delta time cannot point to a certain month because there is no calendar for delta time.

 

R

Message 4 of 13
(3,744 Views)
Yes there is a big difference between relative time which can only be represented as sec, min, hrs, days or years(ignoring leap year starts).  For dime differences you can not talk about montsh unlsee you know the freame of reference.  I do use the subtract to get relative time diferences between 2 time stamps.  I dont think is is all that clear that the units are difference in seconds returned.  Sometimes I multiply this by 1 sec (unit string) so that I can easily change between units in the fromt panel.
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 5 of 13
(3,739 Views)
Solution
Accepted by topic author alecjcook

Alec,

 

See the attached example...  Let us know if it waht you were looking for.

 

The example is an ActionEngine.  Simply select "Start Time/Date" and run it.  Later, select "Get elapsed time" to get the numebr of days / hours / minutes / seconds that have elapsed since the Start Time/Date was selected.

 

R

 

 

 

Message 6 of 13
(3,697 Views)
Excellent! thanks so much!
0 Kudos
Message 7 of 13
(3,670 Views)

Glad to help.

 

You can clean up the example by removing unnecessary items such as the three items at the top (Start Date, Current Dat, seconds).  I had left them in for "debug".  You can then wire the control (enumerator) and indicators to the connector pane (top right below the icon).  That will allow you to use the VI as an ActionEngine right into your own software.  

 

If you plan to use the code into your existing code, you'll have to be careful on how you implement it.  For instance you could take the initial start time(timestamp)at the appropriate location within your code andbring the wire to the appropriate location in your code where you would copy/paste the code within the "Get Elapsed Time" state.

 

R

Message 8 of 13
(3,656 Views)

@Ray.R, I realize this is an old thread but wondering if you could clarify your last statement or provide an example of the usage?  You wrote:

"... bring the wire to the appropriate location in your code where you would copy/paste the code within the "Get Elapsed Time" state."

 I don't understand the copy/paste portion.  Couldn't you wire the Enum to a connector? Then simply drop the VI where you need it, passing in the desired action via the Enum?  Thanks!

 

Never mind!  I got it!

0 Kudos
Message 9 of 13
(2,991 Views)

The resetValues Enum state doesn't seem to reset the seconds field.

0 Kudos
Message 10 of 13
(2,981 Views)