Handlebars - Date and Time Formatting

This article is about using Handlebars to reference questions in custom PDF, Word, and HTML documents. We recommend reading about Basic Question References and Advanced Question References before trying this.

Available on the Advanced and Enterprise tiers:

Essentials
Advanced
Enterprise

About

A mobile form can collect data in a number of formats. The answers from Date, Time, and Date/Time questions are formatted by default in a particular way, but there are options for formatting those answers differently in documents that use Handlebars.

Default Data Formats

The examples below show the default formatting for dates, times, and date/times in raw JSON.

  • Date:
     "Date" : [ "2019-01-21" ]
  • Time: 
     "Time" : [ {
          "provided" : {
            "time" : "12:36:52-05:00",
            "zone" : "America/Atikokan"
          },
          "shifted" : "12:36:52-05:00"
        } ]
  • Date/Time: 
     "DateTime" : [ {
          "provided" : {
            "time" : "2019-01-21T12:36:52-05:00",
            "zone" : "America/Atikokan"
          },
          "shifted" : "2019-01-21T12:36:52-05:00"
        } ],

Provided and Shifted Time

  • The provided time shows the time in the device time zone.

  • The shifted time depends on the Document Time Zone Source, as described in the following table. The examples show the UTC offset for each time zone.

    Note:The device time zone refers to the device setting, not the user profile locale settings in the TrueContext Mobile App account details.

    If the Document Time Zone Source is set to… Then the shifted time is in the… Examples
    Form Submission Device time zone, which is the provided time. In this case, the provided time and the shifted time are the same.

    Date Time of Incident - provided time: 2024-06-04T22:07:00+01:00

    Date Time of Incident - shifted: 2024-06-04T22:07:00+01:00

    Team Preference Setting

    Team time zone

    Date Time of Incident - provided time: 2024-06-04T22:07:00+01:00

    Date Time of Incident - shifted: 2024-06-04T14:07:00-07:00

    Custom The custom time zone that you specify

    Date Time of Incident - provided time: 2024-06-04T22:07:00+01:00

    Date Time of Incident - shifted: 2024-06-04T23:07:00+02:00

Formatting Dates and Times in Handlebars

To format a date, time, or date/time in Handlebars, use the TrueContext custom date/time formatting helper, described below. 

Info:We’re now TrueContext.

General Format

Use the following string wherever you would like to print out a formatted date, time, or date/time.

{{pf:[dataType] answers.myQuestionLabel.0 [format] [timezone]}}

Tip:The "pf" indicates this is a custom TrueContext helper.

  • dataType: Replace with the data type of the question you are formatting (dateFormat, timeFormat, or dateTimeFormat). These are case-sensitive.
  • format: The format you would like to output.
  • timezone: The timezone you would like to format it in. This is optional. Use one of the codes from this list of tz database time zones.

Examples

Notes

  • When including spaces or commas in the format, you must wrap the format in quotation marks (").
  • When including content that is not part of the simple formatting patterns—such as a word like "on" or "at"—wrap the content in single quotation marks (').

Date

To output the format: 2001-07

{{pf:dateFormat answers.Date.0 "YYYY-MM"}}

To output the format: Mon, January 21, 2019

{{pf:dateFormat answers.Date.0 "EEE, MMMM DD, YYYY"}}

Time

To output the format: 1:15 PM

{{pf:timeFormat answers.Time.0 "h:mm a"}}

Date/Time

To output the format: 13:12 on Mon, 21 Jan 2019

{{pf:dateTimeFormat answers.DateTime.0 "HH:mm 'on' EEE, d MMM yyyy "}}