Skip to main content
The autodate field automatically sets the current date and time when records are created or updated. It’s commonly used for created and updated timestamp fields.

Configuration options

bool
default:"false"
When true, automatically sets the current datetime when the record is created.
bool
default:"false"
When true, automatically updates to the current datetime whenever the record is updated.
At least one of onCreate or onUpdate must be enabled. Both can be enabled simultaneously.

How it works

The autodate field has special behavior:
  1. Automatic setting: The value is automatically set during create/update operations
  2. Read-only via Set(): Calling record.Set() on an autodate field has no effect
  3. Manual override: You can manually set values using record.SetRaw() if needed
  4. System fields: If the field is marked as system, the onCreate and onUpdate settings cannot be changed
The autodate field uses a no-op setter, which means record.Set() calls are ignored. Use record.SetRaw() if you need to manually override the timestamp.

Go examples

Database column type

Autodate fields store timestamps as ISO 8601 formatted strings, the same as regular date fields.

Common patterns

System fields

Base collections automatically include autodate system fields:
System autodate fields cannot have their onCreate or onUpdate settings changed to maintain consistency across all PocketBase collections.

Reading autodate values

Filtering by autodate fields

Use cases

When to use onCreate only:
  • Tracking creation timestamp (standard created field)
  • Recording when content was first published
  • Audit trail: when a record was first inserted
When to use onUpdate only:
  • Tracking last modification (when you don’t care about creation)
  • Cache invalidation timestamps
When to use both:
  • Standard updated field that needs an initial value
  • Activity tracking that should always show last interaction
  • Last accessed/viewed timestamps

Best practices

  • Use the standard created and updated system fields when possible
  • Only create additional autodate fields when you need specific behavior
  • Remember that record.Set() doesn’t work on autodate fields
  • Use SetRaw() for manual overrides (like backdating records)
  • Consider using regular date fields if you need user-controllable dates
  • Autodate fields are always in UTC

Comparison with date field

Zero value

The zero value for autodate fields is a zero types.DateTime, but in practice autodate fields are typically always set automatically.