How to Make Excel Formatted Date/Time in LabWindows/CVI User Interface

Updated Jul 28, 2022

Environment

Software

  • LabWindows/CVI

Excel represents Date data as a number of days since January 1, 1900. There is an error with this representation though. In order to get the correct number of days, you will need to subtract 2 days. For more information about this look at the following [External] link.

 

In order to convert the Double data being imported from excel you will need to do some manipulation on the double, and then convert it using the time library.
 

The next step is to use the windows time library. You may use the code snippet found at the following URL to perform the conversion: http://www.thinkage.ca/english/gcos/expl/c/lib/strfti.html . You must modify the double you obtain from Excel in order to make it compatible with the time library. The time library accepts arguments of the form "number of seconds from EPOCH." The double you obtain is the number of days from EPOCH. The conversion looks as below:

 

double obtainedDateDoubleFromExcel;

double convertedDate;

convertedDate = (obtainedDateDoubleFromExcel - 2) * 24 * 60 * 60;

 

You may go on to modify the snippet at the above mentioned URL in the following way:

 

char s[30];

size_t i;

struct tm tim;

time_t now;

now = convertedDate;

tim = *(localtime(&now));

i = strftime(s,30,"%b %d, %Y\n",&tim);

 

 

 

After using the code and following the instructions in the solution section instead of setting "now" to "time(NULL)," you will be setting it to the convertedDate.