How to convert weewx internal dates to standard forms?

135 views
Skip to first unread message

Jonathan Ryshpan

unread,
Oct 25, 2021, 11:49:39 AM10/25/21
to weewx...@googlegroups.com
I have just exported my weewx archive into a csv file; all seems in order, except that the dates are in internal weewx format, which needs to be converted to my own preferred format (which is, for this moment, 2021-10-25 08:36).  How is the conversion made?  

If a formula isn't handy, one can be easily derives using the key numbers of the weewx dating system:  Dates similar to weewx internal dates, are expressed in terms of an epoch, time zero in some generally known dating system, and an interval, the time represented by a change of one unit in the internal dating system. In Unix
the epoch is 00:00:00 UTC on 1 January 1970
and the interval is 1 second.
What are the epoch and interval for weewx internal dates?

-- 
Sincerely Jonathan Ryshpan <jon...@pacbell.net>

	Fiat justitia, ruant coelis!

vince

unread,
Oct 25, 2021, 11:58:30 AM10/25/21
to weewx-user
dateTime is epoch time
interval typically is your archive interval (typically 5 minutes but some folks/stations set theirs differently)

wfs...@gmail.com

unread,
Oct 26, 2021, 8:30:17 AM10/26/21
to weewx-user
If you use sqlite, you can use the sqlite3 utility program to convert the datetimes while exporting.  Start sqlite3 and enter these commands

.open /var/lib/weewx/weewx.sdb
.output export1.csv
.mode csv
.headers on
select datetime(datetime, 'unixepoch', 'localtime') as dt, * from archive;
.exit

The * in the select statement means "every column in the table" so each row in your export will be the converted datetime followed by all columns in the archive table.  You could replace the * with individual column names if you don't need everything.  Example:
select datetime(datetime, 'unixepoch', 'localtime') as dt, outtemp, outhumidity, barometer, rain from archive;

Walt

Jonathan Ryshpan

unread,
Nov 9, 2021, 10:09:32 AM11/9/21
to weewx-user
Thanks.  Somehow neither replies has showed up on my email reader, but they are available on the web site, which explains this late reply.

An easier way to convert appears in an old posting on a LibreOffice list:
Reply all
Reply to author
Forward
0 new messages