Skip to main content
The date field stores a single date and time value using PocketBase’s types.DateTime type. You can optionally enforce min/max date constraints for validation.

Configuration options

min
types.DateTime
Minimum allowed date value. Leave empty to skip the validator.
max
types.DateTime
Maximum allowed date value. Leave empty to skip the validator.
required
bool
default:"false"
When true, requires the field value to be a non-zero date time.

Validation rules

The date field validates:
  • Type: Value must be a valid types.DateTime
  • Min date: If specified, value must be on or after the minimum date
  • Max date: If specified, value must be on or before the maximum date
  • Required: If enabled, value cannot be zero (empty)

Go examples

import (
    "github.com/pocketbase/pocketbase/core"
    "github.com/pocketbase/pocketbase/tools/types"
)

field := &core.DateField{
    Name:     "publishedAt",
    Required: false,
}

collection.Fields.Add(field)

// Set field value
now := types.NowDateTime()
record.Set("publishedAt", now)

Database column type

TEXT DEFAULT '' NOT NULL
Dates are stored as ISO 8601 formatted strings in the database but handled as types.DateTime objects in Go.

Date format

PocketBase uses ISO 8601 format for dates:
import "github.com/pocketbase/pocketbase/tools/types"

// From string
date, err := types.ParseDateTime("2024-03-15 14:30:00.000Z")

// Current time
now := types.NowDateTime()

// From time.Time
import "time"
t := time.Now()
date := types.DateTime{Time: t}

Common use cases

field := &core.DateField{
    Name:     "deadline",
    Required: true,
}

Best practices

  • Use types.NowDateTime() for current timestamp
  • Set appropriate min/max constraints to prevent invalid dates
  • For created/updated timestamps, consider using the autodate field instead
  • Dates are stored in UTC, plan timezone handling accordingly
  • Use IsZero() to check if a date field is empty

Zero value

The zero value for date fields is a zero types.DateTime, which you can check using the IsZero() method.