Handlebars Helper Function: datePart
Extracts a specified part of a date or timestamp, such as the day, month, or year.
This helper is available in the Winter ’27 release of Marketing Cloud Next.
| Parameter | Type | Description |
|---|---|---|
date | String or Object | Required. The date or timestamp from which to extract a date part. |
datePart | String | Required. The date part to extract. Possible values: Y (year), M (month), D (day), H (hour), or MI (minute). |
Specify date in these formats:
-
US formats:
MM/dd/yyyy,M/d/yyyy,MM/dd/yyyy HH:mm:ss,M/d/yyyy h:mm a, orM/d/yyyy h:mm:ss a -
ISO formats:
yyyy-MM-dd,yyyy-MM-dd HH:mm:ss,yyyy-MM-dd'T'HH:mm:ss, oryyyy-MM-dd'T'HH:mm:ss.SSSZ -
12-hour time:
M/d/yyyy h:mm a,yyyy-MM-dd h:mm a, oryyyy-MM-dd h:mm:ss a -
Time-only:
h:mm aorh:mm:ss aIf you specify only a time, the helper function uses the current date.
-
Long-form English:
d MMMM yyyy,MMMM d, yyyy, orEEEE, MMMM d, yyyy -
Chinese or Japanese notation:
yyyy年M月d日 -
Korean notation:
yyyy년 M월 d일oryyyy년M월d일
The function returns the requested date part as an integer. For example, {{datePart "2023年8月5日" "Y"}} returns 2023.