LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format elapsed time

I want to produce 2 strings, one with YYYY:MM:DD and one with HH:MM:SS since a fixed point (when measurements start). I've tried may approaches and searched the examples but could not find what I needed, either I get 1904:01:01 01:00:00 as the starting point or I get negative e.g. seconds when the system goes from 10 to 11 minutes. (same with hours/minutes and so on).
 
Suggestions? Below are a few attemps...maybe a lot of unnecessary code...but not very failiar with labview.
 
/Anders
 


Message Edited by Tohatsu on 01-16-2008 09:13 AM
Download All
0 Kudos
Message 1 of 13
(4,852 Views)
Hi Anders,

atleast you can replace all those "Number to fractional" and "concat string" functions with just 2 "Format into string" functions (format string "%02d:%02d:%02d:;" to get "HH:MM:SS:;")!
Btw. when converting integers to strings you should use "decimal number to string" instead of "fractional number to string" with precision=0!

I also would remove those 2 "value" property nodes with a wire as you get the value from a local control... You also don't need the negate functions, just swap the input of the select functions.



Message Edited by GerdW on 01-16-2008 04:49 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(4,841 Views)
What result are you looking for?  The difference between now and 5 seconds from now is 5 seconds.  That is 0 years, 0 months, 0 days ..... 0 minutes, 5 seconds.  The start of Labview time is 1/1/1904 and I believe midnight UTC.  So formatting a time differential into a date is kind of  meaningless.  If you do subtraction of the time clusters like you do in screenshot #2, then you would wind up with negative parts of time.  You'd have to resolve it back to time stamps.  Note that the earlier version of labview had a lot of bugs converting unusual time clusters to valid timestamps.  And even LV 8.5 still has one error in that function.  For example, month 3 day 33 is not a logical date, but without the bug it resolves to April 2.  Great.  With the bug, it gives an invalid time stamp.
 
Why not do the subtraction on the time stamps, and use the Format Date/String function on the timing palette and format the string the way you want to?
0 Kudos
Message 3 of 13
(4,835 Views)
You can just use a numeric or timestamp control, but change its format to relative time instead of absolute time. You can even select the advanced mode and change a lot of things in the formatting.

___________________
Try to take over the world!
0 Kudos
Message 4 of 13
(4,831 Views)

Try this one.

 



Message Edited by Eugen Graf on 01-16-2008 10:01 AM
Download All
Message 5 of 13
(4,828 Views)

To clarify - use the first example you posted and create an indicator immediately after the subtraction. Then, right click it, select Properties, go to the format page and select relative time.

To learn more about LabVIEW, I suggest you try looking at some of these tutorials.


___________________
Try to take over the world!
0 Kudos
Message 6 of 13
(4,825 Views)


@GerdW wrote:
I also would remove those 2 "value" property nodes with a wire as you get the value from a local control... You also don't need the negate functions, just swap the input of the select functions.



Message Edited by GerdW on 01-16-2008 04:49 PM




Is there any drawback on using the property nodes isntead of wires? cause the controls are quite far away, and nodes seemed to cealn up the code...

I know I can swap the inputs, but there is much code you don't see and I use the inputs in many other places, and to follow some kind of consistency, I kept all the empty stings in the "true" inputs and vice versa.


Thanx for many good answers btw, I'll give them a try at work tomorrow.

Anders
0 Kudos
Message 7 of 13
(4,795 Views)
hi
 
definitive yes. It is always better to use the wire than a property node.
 
Mike
0 Kudos
Message 8 of 13
(4,792 Views)
Using locals instaed of a wire is more time consuming and can generate race conditions when you don't put everything in a sequence frame


other thaught: ONLY USE SEQUENCE FRAMES ONE AT A TIME.
and if you use a sequence frame use a flat sequence
greetings from the Netherlands
0 Kudos
Message 9 of 13
(4,791 Views)


Ravens Fan wrote:
What result are you looking for?  The difference between now and 5 seconds from now is 5 seconds.  That is 0 years, 0 months, 0 days ..... 0 minutes, 5 seconds.  The start of Labview time is 1/1/1904 and I believe midnight UTC.  So formatting a time differential into a date is kind of  meaningless. 

That is exactly what I want, 0 years, 0 months, 0 days, 0hours, 0 minutes and 5 seconds if the loop has been running for 5 seconds. The program can be ran from a few hours up to several months (or atleast 3 weeks). When following the suggestions all of you gave, all I get is string1: 1904:1:1 and string2:1:0:1 as the first value, and I want 0:0:0 and 0:0:1...sure I can subtract those values before the string conversion, but that feels kinda...cheap?
 
Anders
0 Kudos
Message 10 of 13
(4,770 Views)