4.1.1. date

Adding a date field will present your users with a group of select boxes to choose a date and/or time from.

Here's an example that displays three select boxes - year, month and date. The year select will have 2000 as the first option and always have the current year plus five years as the last option:

<field id="mydate" type="date" multiLingual="0">
  <title lang="en">Date</title>
  <title lang="da">Dato</title>
  <format>Ymd</format>
  <year min="2000" max="+5"/>
</field>

Besides the generic title elements you can provide one or two of the following elements to style and configure the date field:

Table 31. Options for configuring a date field

ElementDescription
format

You can determine which select boxes to display in the administration, using single letter shorthands - see the table below for available shorthands.

In addition to the shorthands you can use these characters to style the select boxes:

  • .

  • ,

  • :

  • -

  • (space)

For example you can do something like this to add the time of day to the field and separate the select boxes a bit:

<format>Ymd, H:i:s</format>
year

This element must have a min and a max attribute. You can either type in explicit years, or you can prefix the values with plus or minus signs to let the select options adjust automatically to the current year.

There is no further validity check, meaning, that if you set min to 2010 and max to -5, in the year 2009 you will get a nice list of options ranging from 2010 and down to 2004, and should you forget a decimal and set min to 200 and max to +10, you will get a rather long select box holding values from 200 to 2019 :D


Below is the complete list of available shorthands for select boxes:

Table 32. Options for formatting a date field

LetterDescription
D

Short names of days

l (lowercase L)

Long names of days

d

Day numbers

M

Short names of months

F

Long names of months

m

Month numbers

Y

Four digit year

y

Two digit year

h

12 hour format

H

23 hour format

i

Minutes

s

Seconds

a

am/pm

A

AM/PM

g

12 hour format without leading zeroes

W

week of the year