Skip to content

[2.x] Change all timestamps in the database to use DATETIME instead of INT or BIGINT #7175

Description

@swampopus

This is in stark defiance of one of my original issues, #6931 :)

I've changed my mind. BIGINT helps us out in 2038, but if I can dream, it would be to use DATETIME for human readability.

I often look through tables directly, or look at values via dpm() or a node's devel tab, and I frequently have to copy and paste the created or changed values into unixtimestamp.com to get a conversion. It would be so nice to just see a human-readable date and time.

Pros

  • Easier for humans to read the date in any context (db, web, mysqldump, etc)
  • Queries are semantically easier to follow. Ex: SELECT * WHERE posted IS BETWEEN (2026-01-01 AND 2026-12-31)
  • Easily handled by strtotime() if you really want to get it back to an int.

Cons

  • In PHP, it can save a little bit of typing & CPU clock cycles if you add date() + 7200, for example, to mean "2 hours from now".
  • I'm sure there's a bunch of code that assumes the database timestamps are going to be ints, and a lot of contrib modules that similarly would need to be updated. It would be a bunch of work, no doubt.
  • To convert to a prettier format than Y-m-d, you'd need to do something like: format_date('pretty', strtotime($dt)); It's a little more wordy.

Discussion

I am curious if anyone out there knows of a good reason to store dates and times as integers. I know Drupal does it, and several other projects as well. Is it just a holdover from a previous era, or are there really benefits to only using ints?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions