Handlebars: Date and Time Formatting

 Note: This feature is a limited release for clients using Version 2 forms. 

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. 

 

 

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"
        } ],

 

Shifted vs. Provided Time

  • Provided means the actual time that the mobile user entered/the form collected, in the mobile user's timezone
  • Shifted means the above value, but translated to your team timezone. 

 [ top ]

 

 

 Formatting Dates & Times in Handlebars

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

 

General Format:

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

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

(the "pf" indicates this is a custom ProntoForms helper)

 

Replace:

 

Examples:

Notes:

  • When including spaces or commas in the format, you will need to wrap the format in quotes.
  • When including content that is NOT part of the simple formatting patterns -- such as a word like "on" or "at", wrap it in single quotes

 

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 "}}

 

  [ top ]

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments