Settings

Theme

Ask HN: Timestamp vs. millis, storing time in database

2 points by govindpatel 9 years ago · 2 comments · 1 min read


Ok. this question usually come to my mind and always I prefer using millis because I think that is the easiest way to store and get the time in database.

But some of my friends prefer using timestamp.

So I just wanted to know, What is the best practise for storing time in database ?

When choosing between timestamp and millis which one you prefer using and why?

gjvc 9 years ago

We have a very similar problem. We keep timestamps in numeric form as "epoch nanos" (nanoseconds from 1970-01-01 00:00) We are using PostgreSQL as the database, and I would very much like to use the native type (TIMESTAMP) [1], but PostgreSQL only keeps TIMESTAMP columns to microseconds, not nanoseconds. :-(

Using the native DBMS types allows use of native DBMS time and interval functionality, unless you like doing it yourself.

See also [2]

[1] https://www.postgresql.org/docs/9.6/static/datatype-datetime...

[2] http://stackoverflow.com/questions/409286/should-i-use-field...

  • govindpatelOP 9 years ago

    we have some tables where we have timestamp and other places we have millis. We are also using postgreSQL database.

    I have asked this question so that I can know whether any other person faces problem like this, it is kind of annoying when I see different ways of storing the time, but not knowing what is the best practise to save time in database.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection