Why are date fields stored as integer in SQLite/MySQL databases? Why are date fields stored as integer in SQLite/MySQL databases? sqlite sqlite

Why are date fields stored as integer in SQLite/MySQL databases?


SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values.

For other databases you have wrong impression. Dates are usually stored as Timestamp or Datetime. Sometimes there are cases when people store UNIX Time defined as the number of seconds that have elapsed since 00:00:00 (UTC), 1970-01-01.

People tend to use UNIX time as it is usually easier to do time calculations/comparison, as you can apply usual mathematical operations to compare them. While with Timestamp/Datetime you might need to use time related functions.

What you mention regarding SQLite, it does not have a special datetime datatype.