Handlebars datePart
Handlebars datePart: returns one part of a date or timestamp as a number, for example the year.
Next
Runtime verified
Test scripts included
Returns one part of a date or timestamp as a number, for example the year.
Syntax
{{datePart date part}}
Returns integer.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
date |
any | Yes | The date or timestamp to read from. |
part |
string | Yes | Component to return: Y, M, D, H, or MI. |
Example
Tested in a Marketing Cloud Next email on 2026-11-22:
{{datePart "2023年8月5日" "Y"}}renders2023, as documented.{{datePart "2025-03-15 14:30:00" "MI"}}renders30, as documented.
Show Next test script
Marketing Cloud Next
Works as documented
Every tested call rendered the documented result. Tested 2026-11-22 by rendering in a Marketing Cloud Next email.
See also
- AMPscript
DatePart— the AMPscript equivalent - Official reference