{"id":61,"date":"2008-04-14T14:41:14","date_gmt":"2008-04-14T19:41:14","guid":{"rendered":"http:\/\/blogs.cae.tntech.edu\/mwr\/2008\/04\/14\/converting-national-instruments-lvm-timestamps-to-excel\/"},"modified":"2024-10-27T14:26:19","modified_gmt":"2024-10-27T14:26:19","slug":"converting-national-instruments-lvm-timestamps-to-excel","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/renfro\/2008\/04\/14\/converting-national-instruments-lvm-timestamps-to-excel\/","title":{"rendered":"Converting National Instruments LVM Timestamps to Excel (UPDATED: and Matlab)"},"content":{"rendered":"<p>A few days ago, I had a student looking into what would be required to periodically log some temperatures and pressures from a long-running furnace experiment, so that he doesn&#8217;t have to babysit it and come back every 30 minutes to record his data. We borrowed a National Instruments USB-6008 data acquisition device and downloaded NI SignalExpress LE to try some things out.<\/p>\n<p>There wasn&#8217;t much of a problem with actually capturing the data, but the timestamps (in column 1) were odd-looking:<\/p>\n<pre>\nLabVIEW Measurement\t\nWriter_Version\t0.92\nReader_Version\t1\nSeparator\tTab\nMulti_Headings\tYes\nX_Columns\tOne\nTime_Pref\tAbsolute\nDate\t2008\/04\/11\nTime\t16:24:24.354863\n***End_of_Header***\t\n\t\nChannels\t1\t\nSamples\t100\t\nDate\t2008\/04\/11\t\nTime\t16:22:45.354864\t\nX_Dimension\tTime\t\nX0\t0.0000000000000000E+0\t\nDelta_X\t1.000000\t\n***End_of_Header***\t\t\nX_Value\tVoltage - Dev1_ai0\tComment\n3.29079376535486410E+9\t2.64872102540972910E+0\n3.29079376635486410E+9\t2.64872102540972910E+0\n3.29079376735486410E+9\t2.64872102540972910E+0\n3.29079376835486410E+9\t2.64872102540972910E+0\n3.29079376935486410E+9\t2.65280301912685700E+0\n3.29079377035486410E+9\t2.65280301912685700E+0\n<\/pre>\n<p>There may be a simple way to reformat them inside SignalExpress LE, but it wasn&#8217;t obvious enough when we looked. So here&#8217;s one solution.<\/p>\n<p>The primary difference between National Instruments&#8217; timestamp format and Excel&#8217;s is that NI counts a real-valued number of seconds since January 1, 1904, while Excel counts a real-valued number of days since January 1, 1900. So<br \/>\nthe formula (A6\/86400)+365*4+2 (convert seconds into days, add four years plus two leap days for 1900 and 1904) will convert NI&#8217;s timestamp value of 3290793765.35486 in cell A6 into an Excel equivalent 39549.8908, or April 11, 2008.<\/p>\n<p>But that&#8217;s not quite enough. The test run we made was at 4:22 PM, and that&#8217;s nowhere near 89% of a full day. Sure enough, putting 39549.8908 into a time format gave us 9:22:45 PM, a full five hours ahead of local time. So there&#8217;s a timezone shift in there, too, and we&#8217;re currently on GMT-5. So strip off the fractional part of the Excel timestamp, offset it by 5\/24, and convert it back into a time. The final resulting spreadsheet in tabular form:<\/p>\n<table border=\"1\">\n<tr align=\"center\">\n<td><\/td>\n<td>A<\/td>\n<td>B<\/td>\n<td>C<\/td>\n<td>D<\/td>\n<td>E<\/td>\n<td>F<\/td>\n<td>G<\/td>\n<td>H<\/td>\n<td>I<\/td>\n<td>J<\/td>\n<\/tr>\n<tr valign=\"bottom\">\n<td>5<\/td>\n<td>Original LVM Time<\/td>\n<td>Original LVM Voltage<\/td>\n<td>Convert Secs to Days<\/td>\n<td>Offset by 4 Years (plus 2 leap days)<\/td>\n<td>Final Date<\/td>\n<td>Time (before timezone offset)<\/td>\n<td>Decimal part of Timestamp<\/td>\n<td>Offset for Timezone<\/td>\n<td>Final Time<\/td>\n<td>Final Date\/Time<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>3290793765.35486<\/td>\n<td>2.64872102540972<\/td>\n<td>=A6\/86400<\/td>\n<td>=C6+365*4+2<\/td>\n<td>=D6\t<\/td>\n<td>=D6<\/td>\n<td>=D6-ROUNDDOWN(D6,0)<\/td>\n<td>=G6+$C$3\/24<\/td>\n<td>=H6<\/td>\n<td>=ROUNDDOWN(E6,0)+H6<\/td>\n<\/tr>\n<\/table>\n<p>where cell C3 contained a -5 for our timezone shift from GMT. Columns E, F, I, and J were all in date, time, or date\/time format as needed. The result in cell J6 could be cut down to <code>=(A6\/86400+365*4+2)+$C$3\/24<\/code> if you&#8217;re in a rush to just convert it.<\/p>\n<p>There may be a math or other error that&#8217;s been compensated for somewhere in here, since I&#8217;m not 100% positive about the 2 leap days. But it does equal out down to the second.<\/p>\n<p><strong>Matlab Addendum:<\/strong><\/p>\n<p>Matlab has another time format altogether &#8212; it uses a real-valued number of days since the zeroth of January, year 0000, whatever that means:<\/p>\n<pre>\n&gt;&gt; datestr(0,0)\n\nans =\n\n00-Jan-0000 00:00:00\n\n&gt;&gt; datestr(1,0)\n\nans =\n\n01-Jan-0000 00:00:00\n\n&gt;&gt; datestr(1\/86400,0)\n\nans =\n\n00-Jan-0000 00:00:01\n<\/pre>\n<p>Since that goes back far enough to include the current Gregorian calendar, Julian calendar, and possibly even the pre-Julian Roman calendar standards, the conversion equation is a bit more obtuse (in particular, the 97 day offset was found entirely by trial and error):<\/p>\n<pre>\ntzoffset=-5;\ndata=dlmread('test1.csv',',',1,0);\ntime=data(:,1);\ntemperature=data(:,2);\ntime=time\/86400+365*1905+97+tzoffset\/24;\nplot(time,temperature);\ndatetick('x',0);\ngrid on;\nxlabel('Time');\nylabel('Temperature');\n<\/pre>\n<p>resulting in the correct plot for the brief experiment:<br \/>\n<img src='http:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2008\/05\/time-temperature.png' alt='Time and Temperature Plot' \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago, I had a student looking into what would be required to periodically log some temperatures and pressures from a long-running furnace experiment, so that he doesn&#8217;t have to babysit it and come back every 30 minutes to record his data. We borrowed a National Instruments USB-6008 data acquisition device and downloaded &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sites.tntech.edu\/renfro\/2008\/04\/14\/converting-national-instruments-lvm-timestamps-to-excel\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Converting National Instruments LVM Timestamps to Excel (UPDATED: and Matlab)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,11,12],"tags":[],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-excel","category-matlab","category-national-instruments","entry"],"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":1,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":471,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/61\/revisions\/471"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}