Compare save times
When storing “time data” in a database, you don’t save values as strings, right? Since only numbers are stored, choosing a numeric data type helps reduce storage space.
The following string and integer types represent the same time.
– String Type
2025/10/25 02:15:25
– Integer Type
1761358525
The “Integer type” value mentioned above is a UNIX timestamp. Including milliseconds adds three more digits. For reference, the format including milliseconds is as follows.
– String Type
2025/10/25 02:15:25.123
– Integer Type
1761358525123
Including milliseconds makes it 13 digits. The lightest option is 10 digits without milliseconds. Since integer types contain only pure numbers without slashes or other symbols, they are lighter as data. Whether to use milliseconds generally depends on whether fine-grained timestamp precision is required.
UNIX timestamps are based on UTC time. Therefore, when using them in Japan Standard Time, a +9 hour adjustment is required. While UNIX timestamps are used to reduce database size, since they represent global time, conversion may be necessary during comparisons depending on the situation.
The method for comparing times varies depending on how values are stored within the database. Whether times are stored in Japan Standard Time or Coordinated Universal Time (UTC) also involves complex considerations.
Keep in mind that integer types are the lightest on the database.