Skip to main content

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

FormatDescription
%aThe abbreviated weekday name (e.g., Sun)
%AThe full weekday name (e.g., Sunday)
%bThe abbreviated month name (e.g., Jan)
%BThe full month name (e.g., January)
%dDay of the month,zero-padded (01..31)
%HHour of the day, 24-hour clock (00..23)
%IHour of the day, 12-hour clock (01..12)
%mMonth of the year,zero-padded (01..12)
%MMinute of the hour,zero-padded (00..59)
%pMeridian indicator, uppercase (AM or PM)
%PMeridian indicator,lowercase (am or pm)
%SSecond of the minute,zero-padded (00..60)
%yYear without a century,zero-padded (00..99)
%YYear 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.