DevHub Docs
  • Welcome
  • Analytics
    • What events are tracked automatically?
    • Custom events
    • Google Analytics
  • API documentation
  • Domains
    • Registering a new domain
    • Renewing a domain
    • Pointing an existing domain
    • Pointing a subdomain of an existing domain
    • Transfer a domain
      • Transfer a domain to another registrar
    • Validating your domain
      • Validate with Google Webmaster Tools
    • Domain expiration process
  • Email accounts
    • Hosted email (rackspace)
      • Configure email clients to use POP or IMAP
  • Forms
    • Form and field options
    • Using fieldsets
    • Spam filtering
    • Configure SMTP For outbound emails
    • Using Marketo forms
  • Google Sheets
  • Hosting options
    • Embed pages
    • Wordpress plugin for path override
    • Server path override
      • Apache configuration
      • IIS configuration
      • NGINX configuration
    • CDN (content delivery network) support
  • Maps
    • Location finder
    • Map options explained
    • Google Maps API keys
  • Privacy
    • OneTrust integration
    • Cookies
  • Reverse proxy
    • Privacy and security
    • Proxy Configuration
    • Proxy Gating
    • Form lead tracking
    • Blocking and Whitelisting
      • Whitelisting Options
      • Google Ads rejections or disapprovals
      • 3rd Party Services/Widgets
      • Common Security System Restrictions or Domain Errors
  • SEO
    • Schema.org support
    • Sitemap XML
    • Enable No Index
  • Site builder
    • Getting Started
    • Images and video
    • Pages and content
      • Using page drafts
      • Adding Text
      • Adding and Managing Pages
      • Adding Images
      • Page templates and Templated pages
      • Maps
    • Redirects
    • Site Settings
    • Style Options
    • Adding a Business and location
    • Adding a site
    • Adding a user
    • Adding Custom Forms
    • Adding HTML to Sites or Pages
    • Blogs
  • SSL and security
    • SSL Troubleshooting
    • SSL certificate install options
      • Use your own purchased SSL certificate
    • Enable HTTPS for Sites and Proxies
  • Support
    • Creating a Zendesk account
    • Ticketing submission workflow
    • Builder URL and Site ID
  • Themes and custom templates
    • Getting started
    • Using macros
    • Using custom fields
    • Using URL parameters
    • Hours of operation
    • Using date and time in templates
    • Template variables
    • Site Builder Markup
      • Avoiding Site Builder CSS and HTML duplication
    • Example themes
      • Location focused page with bootstrap
      • Store locator theme example
    • Advanced Examples
      • Theme module templates
      • Static Google maps
      • Content translations
      • Page navigation
      • Override page title and meta tags
      • Adding line breaks to content
      • Get objects
      • Handling boolean values
      • Right to left languages
      • Access current URL
      • Social sharing links
      • Standard filters
      • Serializing data to JSON
      • Form events
      • Schema.org FAQ utility
  • Trace technology
    • What is Trace?
    • Configuration options
  • Data Sources
    • External Contexts
Powered by GitBook
On this page
  • Template utilities
  • datefmt
  • timefmt
  • now
  • day_name
  • to_date
  • to_datetime
  • to_time
  • from_timestamp
  • Hide content based on date
  • Today, future, or past comparisons
  • is_today
  • is_future
  • is_past
  • Combining the above filters
  • Using now to compare to the current day and time
  • Starting on a date
  • Up to a date
  • Date range

Was this helpful?

  1. Themes and custom templates

Using date and time in templates

Formatting and comparison on dates and times

PreviousHours of operationNextTemplate variables

Last updated 1 year ago

Was this helpful?

Template utilities

datefmt

Format a date/time to output a specific format.

Example

Output

{{ timestamp|datefmt('long') }}

January 1, 2024

{{ timestamp|datefmt('Y') }}

2024

More examples of the formats available can be found here:

timefmt

Format a time to output a specific format.

Example
Output

{{ timevalue|timefmt('short') }}

3:23 PM

{{ timestamp|timefmt('a') }}

PM

More examples of the formats available can be found here:

now

This is quick access to the current date and time

<p>The current date is: {{ now|datefmt('MMMM d') }}</p>

Output

<p>The current date is: January 1</p>

day_name

Output the name of the day using the "0 index" of the day of the week.

{{ 3|day_name }}

Output

Wednesday

to_date

Utility to parse a date from a string

{{ '2021-09-01'|to_date }}

Optionally, you can also pass a format to the parsing

{{ '9/1/2021'|to_date(format='%m/%d/%y') }}

to_datetime

Utility to parse a date and time from a string

{{ '2021-09-01 15:23:00'|to_datetime }}

to_time

Utility to parse a time from a string

{{ '15:23'|to_time }}

Optionally, you can also pass a format to the parsing

{{ '1523'|to_time(format='%H%M') }}

from_timestamp

Can be used to convert unix timestamps (i.e. an integer) into date/time to be used by other functions.

{{ 1284101485|from_timestamp|datefmt('long') }}

Output

September 9, 2010

Hide content based on date

Using the advanced jinja2 templating to hide a piece of content depending on the date. This can be used to have something show up before/after/during a date range.

This uses our to_date jinja filter. Take note of the greater than and less than operators.

The to_date is parsed as the first minute and hour of the day so using greater and less than operators is the best way to write the conditionals.

Today, future, or past comparisons

is_today

Show something if the date is today

{% if '2018-12-11'|to_date|is_today %}
  <p>I will show if Dec 12, 2018 is today</p>
{% endif %}

is_future

Show something if the date is in the future

{% if '2018-12-11'|to_date|is_future %}
  <p>I will show if Dec 12, 2018 is in the future</p>
{% endif %}

is_past

Show something if the date is in the past

{% if '2018-12-11'|to_date|is_past %}
  <p>I will show if Dec 12, 2018 is in the past</p>
{% endif %}

Combining the above filters

Show something if the date is today or in the future

{% if '2018-12-11'|to_date|is_today or '2018-12-11'|to_date|is_future %}
  <p>I will show if Dec 12, 2018 is today or is in the future</p>
{% endif %}

Using now to compare to the current day and time

The now is the current date and time

Starting on a date

{% if now > '2018-12-11'|to_date %}
  <p>I will start showing on Dec 11, 2018</p>
{% endif %}

Up to a date

{% if now < '2018-12-11'|to_date %}
  <p>I will stop showing on Dec 11, 2018</p>
{% endif %}

Date range

{% if now > '2018-12-01'|to_date and now < '2019-01-01'|to_date %}
  <p>I will show for the whole month of December</p>
{% endif %}
http://babel.pocoo.org/en/latest/dates.html#date-fields
https://babel.pocoo.org/en/latest/dates.html#time-fields