Pop Tags

Date Fields

A date field adds a handy date picker widget to the form. We’ll see later how you can use the built in search engine to do more advanced queries based on date fields when pulling content into templates.

By default all contents have 3 built-in date fields that are kept up to date automatically. These are:

  1. created_at
  2. updated_at
  3. published_at

Note: The published_at date can also be edited manually.

When using a date field in a template you can use the format attribute to control how the date should be displayed. Here’s a simple example of formatting a date:

<pop:published_at format="mm/dd/yyyy"/>

This would output something like 07/16/2012. Here’s a full list of the symbols you can use in a format string:

d 1 or 2 digit day - no leading 0
dd 2 digit day - leading 0
ddd 3 letter day
dddd full day name
m 1 or 2 digit month - no leading 0
mm 2 digit month - leading 0
mmm 3 letter month name
mmmm full month name
yy 2 digit year
yyyy 4 digit year
h 2 digit time (01-12) - no leading 0
H 1 or 2 digit time (0-24)
HH 2 digit time (00-24)
M 1 or 2 digit minutes
MM 2 digit minutes - leading 0
s 1 or 2 digit seconds
ss 2 digit seconds
t "a" or "p"
tt "am" or "pm"
T "A" or "P"
TT "AM" or "PM"

You can also use the value time_ago_in_words when formatting a date and you’ll get something like “2 hours”. An example:

This post was published <pop:published_at format="time_ago_in_words"/> ago.

Would display something like:

This post was published 2 months ago.

You can specify a language when formatting a date, to make sure the month and day names gets displayed correctly. We currently support:

English en (the default)
Spanish es
Swedish se
German de
Norwegian - Nynorsk nn
Norwegian - Bokmål nb

Feel free to ask for your language of choice, and we'll add it in! Outputting a formatted date by time ago in words in Spanish would look like this:

<pop:published_at format="time_ago_in_words" lang="es"/>
Continue to Number Fields »