Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

UTC and Local Data tables simultaneously


Curt_Ingram May 8, 2019 07:11 AM

Is it possible to have one data table (Weather_UTC) store measurements in UTC, and have another store in local time (Weather_CST)?  This would be good for using the data in different softwares.

Thanks!

Curt


notcabbage May 15, 2019 11:05 PM

Sure. First decide if you want reference time to be in UTC, Local Standard, or Local Daylight time.

There are two ways to do this: either return another time stamp in date-time format or return a string. Returning date-time format helps with pushing the data into a SQL server or other. However, returning a string, the data logger automatically handles the offset conversion based on the "UTCOffset" setting (applicable for CR6 and CR1000X loggers {and maybe others}).

I live in Central Standard Time so my offset is -6 hours. So I set my "UTCOffset" to -21,600 seconds in Device Configuration Utility.

I'll demo using UTC as my station time and converting to local time for my additional table field. (CR1000X)

Public PTemp, Batt_volt
Public UTCOffset As Long
Public TmStamp_Local As Long
Public TmStamp_Local_Str As String * 52

DataTable (Test,1,-1) 'Set table size to # of records, or -1 to autoallocate.
	DataInterval (0,15,Sec,10)
	Minimum (1,Batt_volt,FP2,False,False)
	Sample (1,PTemp,FP2)
	Sample (1,TmStamp_Local,NSec)
	Sample (1,TmStamp_Local_Str,String)
EndTable

BeginProg
	Scan (1,Sec,0,0)
		PanelTemp (PTemp,60)
		Battery (Batt_volt)
    		UTCOffset = 6*3600-DaylightSavingUS(-1)
    		TmStamp_Local = Public.TimeStamp(1,1) - UTCOffset
    		TmStamp_Local_Str = Public.TimeStamp(2,1)
		CallTable Test
	NextScan
EndProg

 And if you're going the other way from Local to UTC, then add on the UTCOffset variable instead of subtract. The way I'm using DaylightSavingUS defaults to normal United States behavior and will automatically adjust the clock using the post-2007 dates. Omit if this doesn't apply.

Log in or register to post/reply in the forum.