According to MySQL internal documentation, this is necessary due to special storage requirements:
+ ----------- + ------------------------ + ------------ --------- +
| YEAR | 1 byte, little endian | Unchanged |
+ ----------- + ------------------------ + ------------ --------- +
| DATE | 3 bytes, little endian | Unchanged |
+ ----------- + ------------------------ + ------------ --------- +
| | | 3 bytes + |
| TIME | 3 bytes, little endian | fractional-seconds |
| | | storage, big endian |
+ ----------- + ------------------------ + ------------ --------- +
| | | 4 bytes + |
| TIMESTAMP | 4 bytes, little endian | fractional-seconds |
| | | storage, big endian |
+ ----------- + ------------------------ + ------------ --------- +
| | | 5 bytes + |
| DATETIME | 8 bytes, little endian | fractional-seconds |
| | | storage, big endian |
+ ----------- + ------------------------ + ------------ --------- +
In particular, DATETIME has 8 bytes:
- 4 bytes: an integer for the date represented as
YYYYร10000 + MMร100 + DD - 4 bytes: an integer in time represented as
HHร10000 + MMร100 + SS
Therefore, it is important to understand that presentation and storage are two different things. As you can see, the structure for datetime is two integers with some internal calculations for both parts - date and time.
source share