I am building a diagram in the MySQL Workbench and this question came to me, what is the difference between the two?
I'm going to work with this base in Java, does java have a problem with any of them?
I am building a diagram in the MySQL Workbench and this question came to me, what is the difference between the two?
I'm going to work with this base in Java, does java have a problem with any of them?
The biggest difference between datetime
and timestamp
is as follows:
datetime
: represents a date as in the calendar and the time as found in the clock. timestamp
: represents a specific point in the timeline and takes into account the time zone in question ( UTC
). For example, when was 26/02/2015 16:40
? depends, for me it is at that time, for Japan it was several hours ago, so basically timestamp
takes into account these time zone issues. Another point is that generally when you need to track changes made to database records, you choose to use timestamp
because it allows you to drill down to the actual timeline.
I'll try an alternative answer.
DATE: Contains only a civil date, with no consideration of time zone, etc. For example, date of birth, or the due date of an account, or a legal deadline, is DATE.
DATETIME: Contains civil date and time, again regardless of time zone. If for example the payment deadline is "day until 13:00", it is the payer's responsibility to know if it's summer time or not.
TIMESTAMP: is a number that determines a specific time. Typically it is expressed as the "number of seconds since 1/1/1970 00:00 in London", but could be any other basis. The idea of timestamp is that it is worth the world, that is, it identifies the exact moment when something happened. An event with timestamp "0" happened on 12/31/1969 at 9:00 PM in Brazil.
The timestamp is useful for logging, and for determining whether A happened before or after B, even though A and B happened on opposite sides of the planet. On the other hand, the timestamp is unsuitable for recording "civil" dates and times because the time and date changes depending on the time zone in which the timestamp is interpreted.
Not always the best option is obvious. For example, register the date of birth with DATETIME or TIMESTAMP? From a mathematical point of view, TIMESTAMP would be ideal because a baby is born at a very specific time. On the other hand, the date and time of birth have civil effects - putting the date of birth different from the Identity Card can cause a lot of hassles - so it's best to use DATETIME and place of birth, since the time zone is known public.