Skip to documentation content

Time Objects

Time Objects

Date, datetime, time, timezone, and time-diff objects.

Time-related object types used when working with dates, times, timezones, and durations in Liquid.

{{ date }}, {{ datetime }}, {{ time }}, {{ timezone }}, and {{ time_diff }} are documented on this page. Format, shift, and convert them with Date Filters. Form markup for date inputs is under Form Fields. {% set_timezone %} lives with Page Metadata.

{{ date }}

A field containing a user-selected date

Properties
Properties of {{ date }} objects
Name Type Description
object_type string Will always be date
is_valid boolean True if the value is not empty
value string Unformatted date string (in UTC)
date {{ time }} An object containing more detailed information about the selected date
default_value string The default value for this field if no value is specified
field_id string The identifier for this field
label string The label for this field
output string The value formatted using the "Short date pattern" (MM/dd/yyyy). May include additional markup in the editor preview to make it easier to edit content

Field used to store a date. All dates are stored in UTC time.

Example Format an entity date field with the date filterFormat an entity date field (e.g. date_opened) for display using the date filter.
Liquid
{%- if entity.date_opened.is_valid -%}
	<p><strong>Date Opened</strong>: {{ entity.date_opened | date: "MMMM dd, yyyy" }}</p>
{%- endif -%}

{{ datetime }}

A field containing a user-selected date

Properties
Properties of {{ datetime }} objects
Name Type Description
object_type string Will always be datetime
is_valid boolean True if the value is not empty
value string Unformatted date string (in UTC)
date {{ time }} An object containing more detailed information about the selected date and time
default_value string The default value for this field if no value is specified
field_id string The identifier for this field
label string The label for this field
output string The value formatted using the "Short date pattern" (MM/dd/yyyy). May include additional markup in the editor preview to make it easier to edit content

Field used to store a date. All dates are stored in UTC time.

Example Access date parts and format time (e.g. am/pm)Access date parts (year, day_of_year, month, day, day_of_week, hour, minute) and format time with am/pm.
Liquid
{%- var meridian = 'am' -%}
{%- var hours = article.post_date.date.hour -%}
{%- if hours > 12 -%}
	{%- set hours = hours | minus: 12 -%}
	{%- set meridian = 'pm' -%}
{%- endif -%}

The year was {{ article.post_date.date.year }}. It had been {{article.post_date.date.day_of_year}} days, or {{ article.post_date.date.month }} months and {{ article.post_date.date.day }} days past the new year. The day was a {{ article.post_date.date.day_of_week }} and the time was {{ hours }}:{{ article.post_date.date.minute }}{{ meridian }}, but that didn't matter.
Example Convert or display dates in a timezone (to_timezone filter)Demonstrates multiple ways to use the to_timezone filter.

Display the article post date in multiple timezones

Liquid
{{ article.post_date | to_timezone: session.user_timezone }} local time
{{- article.post_date | to_timezone: 'UTC' }} UTC
{{- article.post_date | to_timezone: 'Europe/Rome' }} CET
Output
2026-02-16 6:00:00 local time
2026-02-16 10:00:00 UTC
2026-02-16 11:00:00 CET

Convert a date to a different timezone and display it with formatting

Liquid
{%- if entity.alt_timezone.is_valid -%}
	{{- entity.alt_date | to_timezone: entity.alt_timezone | date: 'f' }} {{ entity.alt_timezone -}}
{%- endif -%}
Output
2026-02-16 12:00:00
Example Use a post_date or date-time field with the date filterUse a post_date or other date-time field and format or compare it with the date filter and date properties.
Liquid
{%- if entity.rehearsal_start.is_valid -%}
	<p>Rehearsal will begin on {{ entity.rehearsal_start | date: "MMMM dd, yyyy 'at' h:m t" }} UTC</p>
{%- endif -%}

{{ time }}

Represents a specific instant in a specific timezone.

Properties
Properties of {{ time }} objects
Name Type Description
object_type string Will always be time
is_valid boolean Will always be true
is_future boolean Will be true if the time is in the future and false if the time is in the past. Prevents the page from being fast-cached past when this would change from true to false
year integer The calendar year
month number The calendar month (1-12)
day integer The calendar day of the month (1-31)
day_of_year integer The day of the year (1-366)
day_of_week integer The day of the week (Monday = 1, Sunday = 7)
hour integer The hour of the day (0-23)
minute integer The minute of the hour (0-59)
second integer The second of the minute (0-59)
offset {{ time_diff }} The utc offset of the timezone at this instant expressed as a time_diff (ranging from -14 to +14 hours)
timezone string The full timezone identifier
timezone_short string The shortened timezone identifier, if applicable, for the given timezone at this instant (may vary depending on time of year, and for some timezones may be the same as the full timezone identifier)
output string The instant output using the ISO 8601 standard (yyyy-MM-ddTHH:mm:ss.fffffff)
Example Access date parts and format time (e.g. am/pm)Access date parts (year, day_of_year, month, day, day_of_week, hour, minute) and format time with am/pm.
Liquid
{%- var meridian = 'am' -%}
{%- var hours = article.post_date.date.hour -%}
{%- if hours > 12 -%}
	{%- set hours = hours | minus: 12 -%}
	{%- set meridian = 'pm' -%}
{%- endif -%}

The year was {{ article.post_date.date.year }}. It had been {{article.post_date.date.day_of_year}} days, or {{ article.post_date.date.month }} months and {{ article.post_date.date.day }} days past the new year. The day was a {{ article.post_date.date.day_of_week }} and the time was {{ hours }}:{{ article.post_date.date.minute }}{{ meridian }}, but that didn't matter.
Example Set the request timezoneSet the request timezone from a string (e.g. IANA zone) so date/time output uses that zone.
Liquid
{%- set_timezone "America/Indianapolis" -%}
{{- request.date | timezone }}
Output
America/Indianapolis
Liquid
{%- var cityname = "Amsterdam" -%}
{%- set_timezone "Europe/" | append: cityname -%}
{{- request.date | timezone }}
Output
Europe/Amsterdam
Example How to use the format filter to format datesFormat dates using standard or custom .NET date formats.
Liquid
{% var sep9 = '2009-09-09 14:00:00Z' | date | to_timezone: 'America/New_York' %}

Format a date as a short date string

Liquid
{{sep9 | format: "d"}}
Output
9/9/2009

Formats a date as a short date string (d = short date).

Format a date as a short date string with the time

Liquid
{{sep9 | format: "g"}}
Output
9/9/2009 10:00 AM

Formats a date as a short date string with the time (g = short date with time).

Format a date as a long date string

Liquid
{{sep9 | format: "D"}}
Output
Sunday, September 9, 2009

Formats a date as a long date string (D = long date).

Format a date as a long date string with the time

Liquid
{{sep9 | format: "f"}}
Output
Sunday, September 9, 2009 10:00 AM

Formats a date as a long date string with the time (f = long date with time).

Format a date according to the ISO 8601 standard

Liquid
{{sep9 | format: "o"}}
Output
9/9/2009 2:00:00 PM

Formats a date according to the ISO 8601 standard (o = round trip format with offset).

Format a date as a sortable date string

Liquid
{{sep9 | format: "u"}}
Output
9/9/2009 2:00:00 PM

Formats a date as a sortable date string (u = universal sortable date in UTC timezone).

Format a date to a long date string using a custom date format string

Liquid
{{sep9 | format: "MMMM dd, yyyy 'at' HH:mm:ss"}}
Output
September 09, 2009 at 10:00:00

Formats a date using a custom .NET date format string.

Format a date to a short date string using a custom date format string

Liquid
{{sep9 | format: "hh:mm tt 'on' MM-dd-yy"}}
Output
10:00 AM on 09-09-09

Formats a date using a custom .NET date format string.

You can also use the date filter to format a date

Liquid
{{sep9 | date: "hh:mm tt 'on' MM-dd-yy"}}
Output
10:00 AM on 09-09-09

The date and format filters use the same format strings for dates, but the date filter can only be used to format dates while the format filter can also be used to format numbers and time diffs.

Example Use math to manipulate datesUse the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.
Liquid
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

Liquid
{{ startdate | add_seconds: 3 }}
Output
9/9/2009 12:00:03 AM
Liquid
{{ startdate | add_seconds: -10239 }}
Output
9/8/2009 9:09:21 PM

add_minutes

Liquid
{{ startdate | add_minutes: 3 }}
Output
9/9/2009 12:03:00 AM
Liquid
{{ startdate | add_minutes: -180 }}
Output
9/8/2009 9:00:00 PM

add_hours

Liquid
{{ startdate | add_hours: 3 }}
Output
9/9/2009 3:00:00 AM
Liquid
{{ startdate | add_hours: -32 }}
Output
9/7/2009 4:00:00 PM

add_days

Liquid
{{ startdate | add_days: 3 }}
Output
9/12/2009 12:00:00 AM
Liquid
{{ startdate | add_days: -2 }}
Output
9/7/2009 12:00:00 AM

add_weeks

Liquid
{{ startdate | add_weeks: 3 }}
Output
9/30/2009 12:00:00 AM
Liquid
{{ startdate | add_weeks: -7 }}
Output
7/22/2009 12:00:00 AM

add_months

Liquid
{{ startdate | add_months: 3 }}
Output
12/9/2009 12:00:00 AM
Liquid
{{ startdate | add_months: -10 }}
Output
11/9/2008 12:00:00 AM

add_years

Liquid
{{ startdate | add_years: 3 }}
Output
9/9/2012 12:00:00 AM
Liquid
{{ startdate | add_years: -1 }}
Output
9/9/2008 12:00:00 AM
Example Get Calendar Entries for the Next MonthSet a date range with midnight and add_months, then fetch the next 30 calendar_entries sorted by start_date.
Liquid
{%- var minDate = "now" | midnight -%}
{%- var maxDate = "now" | midnight | add_months: 1 -%}
{%- calendar_entries var entries = start_date:minDate end_date:maxDate limit:30 sort_by:"start_date" sort_direction:"asc" -%}

{{ timezone }}

Properties
Properties of {{ timezone }} objects
Name Type Description
object_type string Will always be timezone
is_valid boolean True if the value is a valid timezone string
value string timezone string
default_value string The default value for this field if no value is specified
field_id string The identifier for this field
label string The label for this field
output string timezone string. May include additional markup in the editor preview to make it easier to edit content

Stores the timezone that should be used when displaying a date and/or time.

{{ time_diff }}

Contains information about the difference between two dates.

Properties
Properties of {{ time_diff }} objects
Name Type Description
object_type string Will always be time_diff
is_valid boolean Will always be true
days integer The number of days between the two dates
hours integer The hours component of the difference between the two dates (eg: if the dates are 25 hours apart this will be 1 since they are 1 day and 1 hour apart)
minutes integer The minutes component of the difference between the two dates (eg: if the dates are 90 minutes apart this will be 30 since they are 1 hour and 30 minutes apart)
seconds integer The seconds component of the difference between the two dates (eg: if the dates are 70 seconds apart this will be 10 since they are 1 minute and 10 seconds apart)
total_days number The total difference between the two dates expressed as whole and fractional days (eg: 25 hours apart would be 1.042 days)
total_hours number The total difference between the two dates expressed as whole and fractional hours (eg: 1 day and 90 minutes apart would be 25.5 hours)
total_minutes number The total difference between the two dates expressed as whole and fractional minutes (eg: 90 minutes, and 10 seconds apart would be 90.167 minutes)
total_seconds number The total difference between the two dates expressed as whole and fractional seconds (eg: 122 seconds and 10 milliseconds apart would be 122.1 seconds)
output string The time diff represented as a string using the standard "constant" format ([-][d.]hh:mm:ss[.fffffff] where all portions of the format in brackets are only included when needed)
Example Compute and display a time difference between two datesCompute and display a time difference between two dates.
Liquid
{%- var diff = request.date | time_diff: calendarEntry.start_date -%}
{%- var is_future = true -%}
{%- if diff.total_seconds < 0 -%}
	{%- set is_future = false -%}
{%- endif -%}
This event {% if is_future %}will start in{% else %}started{% endif -%}
	{%- if diff.days > 0 %}{{diff.days }} days{% endif -%}
	{%- if diff.hours > 0 %}{{diff.hours }} hours{% endif -%} 
	{%- if diff.minutes > 0 %}{{diff.minutes }} minutes{% endif -%} 
	{%- if diff.hours == 0 and diff.seconds > 0 %}{{diff.seconds }} seconds{% endif -%}
	{%- unless is_future %}ago{% endunless -%}
Example How to use the format filter to format time diffsFormat time diffs using standard or custom .NET TimeSpan formats.
Liquid
{% var startdate = '2009-09-09 14:00:00Z' | date | to_timezone: 'America/New_York' %}
{% var enddate = '2009-09-10 17:32:00Z' | date | to_timezone: 'America/New_York' %}
{% var diff = startdate | time_diff: enddate %}

Format a time diff as a constant time span string

Liquid
{{ diff | format: "c" }}
Output
-1.03:32:00

Formats a time diff as a constant time span string (c = constant time span).

Format a time diff as a compact time span string

Liquid
{{ diff | format: "g" }}
Output
-1:3:32:00

Format a time diff using a custom .NET TimeSpan format string

Liquid
{% if diff.total_seconds < 0 %}-{% endif %}{{ diff | format: "d' days, 'h' hours, and 'm' minutes'" }}
Output
-1 days, 3 hours, and 32 minutes

Formats a time diff using a custom .NET TimeSpan format string. Since custom .NET TimeSpan format strings do not have a way to output the minus sign for negative time spans, you have to check for negative time spans separately.