Time and date format in Weewx database

220 views
Skip to first unread message

Phillip Fischer

unread,
Nov 4, 2022, 4:38:13 AM11/4/22
to weewx-user
I hope that someone would be able to point me in the right direction.

I am aiming to use Weewx to log data from a weather station console of a station that is set up in a remote, out of the way area as part of my research. Due to an oversight in Station specs, I was given a station that will need to be downloaded every two weeks or else the data is overwritten, but getting to the site every two weeks is not going to happen!

I've got the station running, connected to a Raspberry Pi Zero 2 and it is working and logging data without issue.

It is easy to get into the .sdb and convert the data to .csv for export to analyse the data off site. There is no cell signal, wifi or any other way of connectivity at the site so the data needs to be physically downloaded.

I am however a bit stumped as I cannot figure out in what format the date and time is stored as. It seems to be a serial number, but I am not sure how to convert that back to Date and Time.

Does anyone perhaps have an idea on how to get the conversion done? I cannot find any explanation in the documentation about the units of the database values.

dateTime
1667481600
1667481900
1667483700
1667484000
1667484300
1667484600
1667484900
1667485200
1667485500
1667485800
1667486100

Stephen Hocking

unread,
Nov 4, 2022, 5:10:55 AM11/4/22
to weewx...@googlegroups.com
Hi Phillip,

It's in Unix Epoch time - this website will help you on how to convert it to a sensible date & time.


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/88e58150-35a5-4841-bea2-452d573b6f6dn%40googlegroups.com.


--
  "I and the public know
  what all schoolchildren learn
  Those to whom evil is done
  Do evil in return"		W.H. Auden, "September 1, 1939"

Glenn McKechnie

unread,
Nov 4, 2022, 5:14:39 AM11/4/22
to weewx...@googlegroups.com
unixepoch, epochtime, unixtime

from a linux terminal...

$ date -d now +'%s'
1667553105

$ date -d @1667553105
Fri 04 Nov 2022 20:11:45 AEDT

man date

within a mysql (mariadb)...
SELECT FROM_UNIXTIME(datetime, '%d-%m-%Y %H:%i') from archive WHERE
dateTime = 1667340000;

there'll be something similar for sqlite
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-user+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/88e58150-35a5-4841-bea2-452d573b6f6dn%40googlegroups.com.
>


--


Cheers
Glenn

rorpi - read only raspberry pi & various weewx addons
https://github.com/glennmckechnie

p q

unread,
Nov 4, 2022, 5:33:50 AM11/4/22
to weewx...@googlegroups.com
A little more background. It's a unix epoch datetime. The number of seconds since 1970 iirc. Google unix epoch.

Phillip Fischer

unread,
Nov 4, 2022, 5:42:58 AM11/4/22
to weewx-user
Thank You! I am fairly new to the world of linux and learning new things each day! I appreciate your time to answer my question.

I've successfully converted the time and date stamps!

Greg Troxel

unread,
Nov 4, 2022, 6:35:10 AM11/4/22
to Phillip Fischer, weewx-user

Phillip Fischer <zs6...@gmail.com> writes:

> Thank You! I am fairly new to the world of linux and learning new things
> each day! I appreciate your time to answer my question.

This is likely beyond what you care about, but note that the time values
are the number of seconds since January 1, 1970 UTC **as if there were
no leap seconds**.

But with weather data every 15 minuts, that just means that occasionally
those timestamps that differ from 900 will be 901 (or maybe in the
future 899 seconds apart). And, surely your weather station doesn't
have leap second support, and your computer doesn't have a network
connection.


But seriously, I don't know how you are dealing with time, and probably
you want to have a GPS receiver and run ntpd to sync the RPI's clock,
and understand how that relates to the weather station's clock.

You probably also want to run the RPI in UTC, and also the weather
stations, so that there is no daylight savings time confusion. weewx
does not as far as I know support "operate in UTC but produce
graphs/summaries in local time (meaning "today" as a 24h period,
min/max, etc.)". But you are just going to process the weewx.sdb
elsewhere.

I would also put a USB SSD or stick in the Pi and back up the weewx.sdb
to that daily, in a way that doesn't overwrite the previous backups.
And a UPS (even a Pi UPS with a battery, but beware of lithium batteries
below freezing).
signature.asc

Tom Keffer

unread,
Nov 4, 2022, 7:28:35 AM11/4/22
to weewx...@googlegroups.com, Phillip Fischer
Not to be too terribly pedantic, but unix time does deal with leap seconds. It's just that it deals with them using a discontinuity at midnight. The result is that if you calculate the difference in unix epoch time between, say, 23:55 and 00:10, it will always be 900 seconds, even if a leap second was inserted in there. However, if you were to calculate the difference in UTC, it would be 901 seconds if a leap second occurred.

99.9% of the time, this is what you want. It's a brilliant solution to a difficult problem. The only problem is that every couple of years or so, there will be a unit timestamp that is ambiguous. There will be two times with the same timestamp. 



--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages