04-17-2015 02:58 PM
I am using the Get Time/Date String.vi to report the time everytime data is taken. Is there an easy way to subtract one time string from another to calculate the time in between data measurements? I need this for excel reporting.
Any help is appreciated!
04-17-2015 03:05 PM
If you are working with strings, you will need to parse them to reconstruct timestamps, then its just a matter of subtraction. It would be easier if you could get at the time values before they are converted into strings.
Mike...
04-20-2015 12:57 AM
I am still fairly new to programming so maybe this is a basic question but how would I go about parsing and reconstructing the strings?
Thanks!
04-20-2015 01:48 AM
04-20-2015 10:35 AM
For the heck of it I attached an example VI. It takes two string controls, formats them into time stamps, and gets the difference in time between them. The format for the time needs to be known and that is what the scan from string uses. If your format is different that's fine, it will just need a string constant that corresponds to your format.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-20-2015 10:54 AM - edited 04-20-2015 11:03 AM
Hoovah shows how to find the difference between two time/date strings in Labview.
While that works I recommend you stop writing time stamps to an Excel file as a time/date string.
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.
Instead of writing a time/date string you should write a double precision number that corresponds to the OLE date that Excel uses.
Now you will find when you open your Excel file the time column will look like a crazy number, simply format the column to the time and/or date format you desire.
You will find that you can now do a running subtraction to show the time between time stamps in Excel.
04-20-2015 11:35 AM
RTSLVU, you missed the leap yer bug correction and, those constants would make more sense if the display format was relative time
04-20-2015 11:40 AM
@JÞB wrote:
RTSLVU, you missed the leap yer bug correction and, those constants would make more sense if the display format was relative time
I don't think I have ran into the Leap Year bug.
Does it just effect Febuary 29th?
04-20-2015 11:59 AM
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.
04-20-2015 12:15 PM
One thing I don't think Excel accepts in this format (correct me if I'm wrong) is fractions of a second. If I try to enter 4/19/2015 5:00:00.123 AM the format is lost and weird things can happen. It tries to recognize it as a number so some math still works but it no longer looks right. Since we are often dealing with DAQ data and quick logging to a CSV it is quite often you'll have a sample more than once a second. Other file formats like TDMS can log the raw time stamp data so there is no loss in precision. In the past I've written TDMS files, then converted them to Excel to be more easily viewable.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord