LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calculate difference between time strings


@nathand wrote:

RTSLVU wrote: 

One of these days it is going to bite you in the behind, as you already have found you can not do any math on a time/date string once it is in Excel.


If the text is properly formatted, Excel will automatically interpret it as a time or date, and you can then do math on it. For example, put the following text in a file, name it with a .csv extension, and open it in Excel, then try subtracting the two timestamps (you may need to modify depending on your local time format, but Excel is pretty flexible about interpreting times and dates).

4/19/2015 5:00 AM,25
4/20/2015 5:00 PM,30

The result will be 1.5 (or -1.5), since Excel treats days as integers, and times as fractions of days.

 

Back when I started LV programing I used to just write the time stamp as formatted text.

 

Then one day an engineer I was working with on a long term project that was collecting 100 data points a minute on six systems 24/7 came to me with a rather angry look on his face and showed me how difficult I made his data analysis because he could not reformat the time column or do math on it to find the exact time between samples.

 

Then I researched it, and have been using the method I showed above and never looked back.

 

We were using Excel 2000 at the time. They must have improved it in more recent Excel versions as you are right in Excel 2013 it handles it correctly. 

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 11 of 17
(2,450 Views)

You can get it to recognize fractional seconds, but you need to enter a custom cell format, it won't do it automatically. For example, you could enter "m/d/yyyy h:mm:ss.000" as a cell format code.


@RTSLVU wrote:

We were using Excel 2000 at the time. They must have improved it in more recent Excel versions as yo uare right in Excel 2013 it handles it correctly.


Yes, I suspect you're right that this is an improvement in Excel, since sometime around 2004 I wrote a very similar VI to what's been posted here for converting timestamps, and I know I needed it then. I've since lost that VI in the course of several job changes and haven't needed it again, though.

0 Kudos
Message 12 of 17
(2,446 Views)

@RTSLVU wrote:

@JÞB wrote:

Or just use these

RTSLVU, you missed the leap yer bug correction and, those constants would make more sense if the display format was relative timeSmiley Wink


I don't think I have ran into the Leap Year bug.

 

Does it just effect Febuary 29th? 


Way back when... some developer forgot to read the fine print from Pope Gregory and put Feb 29 1900 on the calender.  Funny they would have fixed the bug in Excel except.... everyone knew that Lotus 1 2 3 had that bug and coded around it.  Odd Stuff happens


"Should be" isn't "Is" -Jay
0 Kudos
Message 13 of 17
(2,440 Views)

Thanks for your reply!

I actually only have one source of the time string (Get Time/Date String.vi) and am using it to calculate when data is being collected in my program as an array. I was hoping to use this to find the difference between when data is collecting (i.e. difference between the new time string and old time string). I thought I could just use a shift register and work in your example but it can't seem to read the data coming in from the shift register. Any ideas as to why that might be? Or is there a better way to do the above?

 

 

0 Kudos
Message 14 of 17
(2,414 Views)

No reason to use Get Date/Time String here! There's already a function to return the current date and time as a timestamp (Get Date/Time in Seconds). The output of that should go to the shift register.

 

Not sure what you mean by "can't seem to read the data coming in from the shift register." Can you post your actual VI? What happens when you run your code with execution highlighting turned on? Also, why don't you trust the "dt" value from the waveform? If the source of that waveform provides consistent timing information, then the dt value is the difference in time between successive data points.

0 Kudos
Message 15 of 17
(2,402 Views)

I initially tried to use the dt vakue because I assumed it would be the easiest way but I found that the value never changed (it was always 00:00:00). Any idea why that would be?

Message 16 of 17
(2,391 Views)

@kmarcella wrote:

I initially tried to use the dt vakue because I assumed it would be the easiest way but I found that the value never changed (it was always 00:00:00). Any idea why that would be?


Look up Waveform in the LabVIEW Help, and you will understand (a) why "the value never changed" (answer -- it's not supposed to change) and (b) why displaying it in Timestamp format is really silly (answer -- it is not a Timestamp).

 

Please -- take time out and go through some LabVIEW tutorials to learn basic LabVIEW skills.  Make use of the LabVIEW Help, try to figure it out yourself.  Find someone at your school, in your company, whatever, who knows LabVIEW and "apprentice" yourself to them.

 

BS

0 Kudos
Message 17 of 17
(2,368 Views)