Example Code

Writing a Timestamp with my Data to a Spreadsheet using LabVIEW

Code and Documents



This VI demonstrates how to add the timestamp of measurement to a spreadsheet using 2 methods, one that updates the file instantaneously, and the other one writes data one time.




These examples allow you to write timestamps along side your data and then export them to a Spreadsheet.  

 In this example you will find  loops:

  1. The first loop shows how to write to the spreadsheet file after all the data has been acquired. It uses the Write to Spreadsheet File.vi and is the easiest of the three to implement.

  2. The second loop writes to the spreadsheet file each time the data and time stamp are generated. This method also uses the Write to Spreadsheet File.vi. This method is not the best, however, since this VI opens, writes to, and closes the spreadsheet file with every time a measurement is taken, consuming CPU time.

 Steps to Implement or Execute Code

1. Open the attached VI "Insert Time stamp into Spreadsheet_LV2012_NI Verified"

2. Enter the path for the first and second loops

3. Run the VI



LabVIEW 2012 (or compatible)



Additional Information or References

Since a spreadsheet file is a specialized type of text file, you need to first convert your data and time stamp into a string.  This can be done via a few different VIs


  1. The time stamp must be wired to either a Get Date/Time String.vi or Format Date/Time String.vi.

  2. Your data must be wired to a string/number conversion VI. Two possibilities are Number to Fractional String.vi for floating point numbers and Number to Decimal String.vi for integers.

  3. Finally, the data and timestamp strings must be joined into a string array. You can do this by wiring the time stamp string and number string to a Build Array.vi.

 Note: you will find in the other attached examples a third loop that writes in the spreadsheet file inside the loop each sample of data. However this method consumes the CPU resources and is not the proper way to write every sample of data specially when loop is running at higher rates (file ill be opened and closed every iteration)



Block Diagram




Front Panel



**This document has been updated to meet the current required format for the NI Code Exchange.**

John B.
Applications Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.