Reformat Date Filters for Scriptlets
The date filters in scriptlets are useful for calculating and manipulating dates. For instance, if you have a Google Form and want to send out an email with the day of the week it was filled on, you can make use of the date filter with the appropriate format.
{? "May 24, 2021" | date: "%A" | prepend: "The day is " ?}
// Output: The day is Monday
{? "{{Date of Birth}}" | date: "%Y" | prepend: "The person was born in " ?}
// Output: The person was born in 2021
Date Formats
Format | Description |
---|---|
%a | The abbreviated weekday name (e.g., Sun) |
%A | The full weekday name (e.g., Sunday) |
%b | The abbreviated month name (e.g., Jan) |
%B | The full month name (e.g., January) |
%d | Day of the month,zero-padded (01..31) |
%H | Hour of the day, 24-hour clock (00..23) |
%I | Hour of the day, 12-hour clock (01..12) |
%m | Month of the year,zero-padded (01..12) |
%M | Minute of the hour,zero-padded (00..59) |
%p | Meridian indicator, uppercase (AM or PM) |
%P | Meridian indicator,lowercase (am or pm) |
%S | Second of the minute,zero-padded (00..60) |
%y | Year without a century,zero-padded (00..99) |
%Y | Year with century (e.g, 2021) |
NOW
You can use the special word now
or today
to get the current date and time and reformat the value with the date filter.
{? "now" | date: "%Y-%m-%d %H:%M %p" | prepend: "This email was generated on " ?}
// Output: This email was generated on 2020-05-24 08:00 AM
{? "January 24, 2021 3:34 PM" | date: "%H:%I %P" ?}
// Output: 15:03 pm
{? "January 24, 2021 3:34 PM" | date: "%a, %b %d, %Y %I:%M %p" ?}
// Output: Sun, Jan 24, 2021 03:34 PM
{? "2021-05-24T04:48:46.623Z" | date: "%Y-%m-%d %H:%M" ?}
// Output: 2021-05-24 10:18
info
All date calculations are done based on the timezone of your Google Spreadsheet.