K
K
Kirill2018-03-15 17:16:46
MySQL
Kirill, 2018-03-15 17:16:46

Choice of time storage format?

Greetings. At me an eternal problem of a choice of a format of storage of time.
When is it better to use DATETIME when just INT for timestamp?
The date / time of birth is DATETIME exactly, but the last update of the record in the database? What criteria should be followed?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2018-03-15
@ThunderCat

Everything is very simple - if it is a date and / or time - use the datetime format, in all other cases the types correspond to the stored data. Int for timestamp is generally obscene in its purest form.
Do you have a date of birth? You can use DATE here, but I would not be stingy and set DATETIME for reasons of uniformity in working with date and time.

A
Alexander Aksentiev, 2018-03-15
@Sanasol

it is more convenient and faster to work with a normal date than with a timestamp number.
In terms of speed on my tests of datetime with an index versus int with an index, the first option won. Although it was obvious that the second should be faster, it turned out that it was not. (In the Mysql database, of course, I won’t speak for others).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question