Skip to content

Date & time

Field.date holds a calendar date and Field.time a time of day. Both store plain strings without a timezone, which makes them easy to compare, filter and sort.

import {Field} from 'alinea'

Field.date('Publish date')
Field.time('Start time', {minValue: '08:00', maxValue: '18:00'})

Options

  • minValue and maxValue (time only): the earliest and latest time an editor can enter, as HH:mm.

  • autoFocus: focus the input when the entry opens.

  • The common options help, width, inline, initialValue, required, validate, readOnly, hidden and shared.

Value

  • A date is stored as an ISO date string, '2026-09-23'. The dashboard shows it in day-month-year order.

  • A time is stored as 'HH:mm' on a 24-hour clock, '14:30'.

  • Both are empty until an editor picks a value, unless you set an initialValue.

Because the format sorts alphabetically in date order, you can filter and sort on these fields directly:

import {cms} from '@/cms'
import {Event} from '@/schema'

const today = new Date().toISOString().slice(0, 10)

const upcoming = await cms.find({
  type: Event,
  filter: {date: {gte: today}},
  orderBy: {asc: Event.date}
})

Default to today

initialValue takes a fixed string. Compute today's date in your config: it's evaluated when the dashboard loads, so new entries get the date the editor opened the dashboard.

import {Field} from 'alinea'

const today = new Date().toISOString().slice(0, 10)
Field.date('Publish date', {initialValue: today})

If the creation date matters, entries made with Config.document already record it: query Query.createdAt.

Formatting

new Date('2026-09-23') is midnight UTC, which is still the previous day in timezones west of UTC. Format stored dates in UTC to show the date the editor picked:

export function formatDate(date: string, locale = 'en-US') {
  return new Date(date).toLocaleDateString(locale, {
    dateStyle: 'long',
    timeZone: 'UTC'
  })
}