From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading time from Excel -- Labwindows/CVI

I am reading data from several Excel files. The files I am reading from contain a column (time) that is time formatted in Excel. When I read a cell from this column, I get a double (ex: .472558) which is no use to me (unless there is a way I can convert this double to a string (ex: 11:05:30). Is there any way I can read the time as a string without manually changing the format of the column in Excel?
0 Kudos
Message 1 of 3
(2,816 Views)
If the Excel cell contains just time, and not time and date, Excel stores the time as a fraction of 24 hours.
E.g.:
12:00 AM = 0.00
6:00 AM = 0.25
12:00 PM = 0.5
Message 2 of 3
(2,816 Views)
Here's some CVI code to build hh:mm:ss from excel time.

// xlTime is the double extracted from an excel cell containing time.
// time String will contain hh:mm:ss
double xlTime;
char timeString[20];
double xlHours, xlMinutes, xlSeconds;

xlHours = floor(xlTime * 24);
xlMinutes = floor((xlTime * 24 - xlHours) * 60);
xlSeconds = floor((((xlTime * 24 - xlHours) * 60) - xlMinutes) * 60);
Fmt (timeString, "%s<%d[w2p0]:%d[w2p0]:%d[w2p0]",
(int) xlHours, (int) xlMinutes, (int) xlSeconds);
0 Kudos
Message 3 of 3
(2,816 Views)