DateTimes in Relational Databases

DateTimes in Relational Databases

(This article's title comic is from Randall Munroe, creator of the XKCD comic, and licensed under CC BY-NC 2.5, you can find the original here).

TL;DR? Check this resource to read-up why I am in the "impossible to know camp"

How dare you to ask me what the difference between two points in time is? You didn't yet provide the necessary information to even consider how to answer it:

  • Which resolution do you want? Are we talking nanoseconds, seconds, days, years, decades or what?
  • Shall we take leap-days and leap-seconds into account or not?
  • Do we have to take timezones into account for T1 and T2? If yes, which ones? And roughly when did these events happen and did the timezones exist then? And where, because the timezones changed in the past? And did they apply timezones at all or are we talking railway or solar time?
  • When did these events take place? Around 5th of October 1582 to 14th October 1582? These days do not even exist in a lot of countries.
  • Where did these events take place? A moon day is roughly 28 earth days, you know.
  • Which day length applies even? If we're talking about eons in difference, we have to take day length into account! And finally:
  • If the (one) observer is far away, do we have to take (general) relativity into account?

Save for the last two, you can read up on this and other quirks on handling DateTime in Richard T. Snodgrass's extremely excellent, “Developing Time-Oriented Database Applications in SQL” (Morgan Kaufmann, 2000 – Yes, it’s old, yes, it is out of print, but yes, it’s still extraordinarily good! You can download it from Richard’s homepage). This is by the way also an excellent treatment of how to handle historization in relational databases!


Time is a fiction, don't rely on it :)

Like
Reply

You would not believe HOW MUCH TIME (sic!) I have already spent to explain, why e.g. IoT backend data designs should never rely on timestamps, but simple monotonous hardware clocks, aka event counters, if the exact order of events is of some relevance. Using "timestamp without timezone" in PostgreSQL is a harmless looking deathtrap, unless you know exactly what you are doing. Another great read about time is the seminal paper on Spanner: https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://research.google.com/archive/spanner-osdi2012.pdf&ved=2ahUKEwiImOPb1pGDAxX9hP0HHW1OCGkQFnoECBEQAQ&usg=AOvVaw0jTMltcXSUju43NRB29vPi

To view or add a comment, sign in

More articles by Jens Scheidtmann

Others also viewed

Explore content categories