4
votes

I'm using SendGrid portal to manage my email templates using handlebar substitutions as its reference in this link https://sendgrid.com/docs/ui/sending-email/using-handlebars/#substitution

I would like to know if it is possible to convert and/or format dates in the SendGrid transactional template portal.

This is my HTML template in SendGrid portal:

<p>This report was generated on {{GenerationTimeUtc}}</p>

This is the dynamic data sent to SendGrid:

{
   "GenerationTimeUtc":"2018-09-14T21:16:30.1467851Z"
}

I would like to show it in a more readable way like "This report was generated on May 04" instead of showing "This report was generated on 2018-09-14T21:16:30.1467851Z"

I'm using SendGrid V3

Thanks in advance.

1
Can't just send the date formatted in the json? - cshapdev
Yes, but that means I'll need to change my code each time the user needs to change the date format. It would be easier if I can change only the template - user4317540

1 Answers

3
votes

You can make use of formatDate for this type of formatting, referencing standard dateTime format flags.

<p>Join us {{formatDate dateString "M d"}}</p>

And similar implementation using a different date format…

<p>Join us {{formatDate dateString "yyyy-mm-dd"}}</p>