A
A
Alexey Sukhorukov2016-05-27 18:28:24
MySQL
Alexey Sukhorukov, 2016-05-27 18:28:24

What is the best way to store dates?

Good afternoon. Do not kick please - just learning.
Such question: how it is correct to store dates in MySQL (and bases basically)?
As I see it: we get a timestamp, write it to the database, when necessary - we pull it out and convert it as we like.
But I heard from many that this is a bad form and dates should be stored in DATE, DATETIME and other things, exclusively in their format.
Please consider and explain in what cases which option is better to use.
Thanks to!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
dom1n1k, 2016-05-27
@Robin34

Roughly speaking, the date is a cell in the calendar, and the time stamp is an instant, a moment in time.
You need to understand what a specific task requires - and choose.
For example.
1. I checked into the hotel on May 22 and checked out on the 26th. We are talking about days here, not specific moments.
2. We write a hit on the site in the logs - this is the moment.

Макс, 2016-05-27
@AloneCoder

Использование unix timestamp избавляет от всяких граблей с таймзонами, секундами координации

Михаил, 2016-05-27
@springimport

В unix t:
+ простота;
- отсутствие зон;
в дате все наоборот.

R
res2001, 2016-05-27
@res2001

If you need to perform operations with dates, for example, add / subtract a day / hour / week, find the last day of the month, figure out if the year is high, find the difference in days between dates, etc. then use datetime (and things like this are done all the time).
In fact, in practice there are not so many uses for timestamp, datetime is used much more often.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question