LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate time difference in Labview from excel file

I am reading in values from a excel files, the file contains date and time data in one cell, then either an On or Off value in the cell next to it. I would like to find the time difference between the on and the off cycles. The VI I have so far brings in the Excel file but I don't know how to subtract the dates. Any help would be appreciated. I have attached the vi and hopefully I can attach and example excel file.
0 Kudos
Message 1 of 8
(3,810 Views)
Heres is an example of the Excel file I am reading
0 Kudos
Message 2 of 8
(3,810 Views)
Since your data is in a fixed format, you can write some simple code to go over the string and convert it to a LabVIEW timestamp, which you can work on. To do this, Write some code that will allow you to read and convert to a number each part of your field (month, year, minute, second...). From the Time & Dialog pallette, take the Seconds to date\time VI and place it on the diagram. Place a "Bundle by name" function near it and wire the output of the VI into "input cluster". Wire your data in, convert the result back using Date\time to seconds and that's it.

___________________
Try to take over the world!
0 Kudos
Message 3 of 8
(3,795 Views)
Hello bryan,

what I want to mention after having a look at your Excel sheet:
perhaps you should convert the format of your time data to normal number (with 6 digits precision?). Then it is much
easier to read and convert those data. Even in Excel it's easier, because you don't have to convert to different
time format (my german Excel doesn't understand your time format and gives me a string instead...)

Hope this helps
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(3,790 Views)
why not just use excel macro to subtract the time? It is much easier. In the end you just need to read in the time difference data into labview.

-Joe
0 Kudos
Message 5 of 8
(3,783 Views)
Joe,
I thought about using an excel macro, but my problem is that the length of the table isn't set it varys between excel sheets. I know little about makeing excel macros so I didn't know how to tell excel to do the macro for X number of cells. How are you with excel macro's?

Thanks
0 Kudos
Message 6 of 8
(3,776 Views)
I tried using macro and it is not very straight forward. I agreee with others, using labview to convert the date/time to seconds and then subtract the data.

-Joe
0 Kudos
Message 7 of 8
(3,762 Views)
Hi Bryan!

I made a small VI (in LabVIEW 7.1) that converts to strings (of your format) to timestamp datatype and then subtracts them resulting in a difference measured in seconds. There might be a more optimal way to do this in your application, but I thought I'd at least try to contribute. Also, notice that there is a Y3K bug in there 🙂

Hope this helps!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 8 of 8
(3,749 Views)