created and updated timestamp fields.
Configuration options
When true, automatically sets the current datetime when the record is created.
When true, automatically updates to the current datetime whenever the record is updated.
How it works
The autodate field has special behavior:- Automatic setting: The value is automatically set during create/update operations
- Read-only via Set(): Calling
record.Set()on an autodate field has no effect - Manual override: You can manually set values using
record.SetRaw()if needed - System fields: If the field is marked as
system, theonCreateandonUpdatesettings 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
- Created timestamp
- Updated timestamp
- Manual override
- Both create and update
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:Reading autodate values
Filtering by autodate fields
Use cases
When to use onCreate only:
- Tracking creation timestamp (standard
createdfield) - Recording when content was first published
- Audit trail: when a record was first inserted
- Tracking last modification (when you don’t care about creation)
- Cache invalidation timestamps
- Standard
updatedfield that needs an initial value - Activity tracking that should always show last interaction
- Last accessed/viewed timestamps
Best practices
- Use the standard
createdandupdatedsystem 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
| Feature | Autodate | Date |
|---|---|---|
| Automatic setting | Yes | No |
Can use record.Set() | No (use SetRaw()) | Yes |
| Validation | None | Min/Max/Required |
| Use case | Timestamps | User input dates |
Zero value
The zero value for autodate fields is a zerotypes.DateTime, but in practice autodate fields are typically always set automatically.