Search⌘ K
AI Features

Change Timestamps

Understand how to adjust Ecto's default timestamps by configuring global Repo settings or migration-level options. Explore using precise UTC timestamps with microsecond accuracy, renaming timestamp columns, and ensuring timestamps work correctly within Ecto schemas. This lesson helps you manage and tailor timestamp data consistently across your Elixir database applications.

Change defaults for timestamps

Earlier, we saw how the timestamps method automatically adds inserted_at and updated_at columns to our tables. By default, these will always use Elixir’s NaiveDateTime type, but we’ll can change this globally in our Repo config. Here’s how we could change it to use a UTC timestamp.

Elixir
config :music_db, MusicDB.Repo, migration_timestamps: [type: :utc_datetime]
...