Date Functions within Freemarker

Freemarker provides powerful formatting options for working with dates, whether you’re displaying timestamps, converting numeric values to date formats, or transforming how a date is shown.

Formatting Date Values

When working with m-Power, it’s recommended to first convert your value to a date using ?date(...) with the correct incoming format. Once the value is treated as a date, you can then format it using ?string(...).

Example

If your field is stored as a string in yyyyMMdd format (e.g., "20030408"), use the following:

${row.ORDERDATE?date("yyyyMMdd")?string["MM/dd/yyyy"]}

Sample Output:

04/08/2003

SimpleDateFormat Pattern Reference Table

Freemarker allows you to use Java’s SimpleDateFormat patterns with the ?string built-in. Below are some common examples:

PatternMeaningExample Output
yYear (e.g., yy = 2-digit, yyyy = 4-digit)03, 2003
MMonth (1–12)4
MMTwo-digit month (01–12)04
MMMAbbreviated month nameApr
MMMMFull month nameApril
dDay of the month (1–31)8
ddTwo-digit day of the month08
EAbbreviated day of the weekTue
EEEEFull day of the weekTuesday
hHour (1–12, no leading zero)9
hhHour (1–12, two digits)09
HHour (0–23, no leading zero)21
HHHour (0–23, two digits)21
mMinutes (0–59)4
mmTwo-digit minutes04
sSeconds (0–59)9
ssTwo-digit seconds09
aAM/PM markerPM
zTime zone abbreviationPDT

Tip: You can mix symbols to get exactly the format you need.

Example Usage in Freemarker

${row.ORDERDATE?date("yyyy-MM-dd")?string["MM/dd/yyyy"]}

Output:

04/08/2003

Other Examples in Freemarker

${row.ORDERDATE?date("yyyyMMdd")?string["dd.MM.yyyy, HH:mm"]}
${row.ORDERDATE?date("yyyyMMdd")?string["EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'"]}
${row.ORDERDATE?date("yyyyMMdd")?string["EEE, MMM d, ''yy"]}

Sample Output:

08.04.2003, 21:24
Tuesday, April 08, 2003, 09:24 PM (PDT)
Tue, Apr 8, '03

Formatting Non-Date Values into Dates

Sometimes, your data might not be a date value but still represent a date component—like a numeric month (e.g., 1, 2, 10). You can still use Freemarker to display these values as formatted dates.

Example: Numeric Month → Month Abbreviation

${row.MONTHNUM?date('M')?string('MMM')}

Sample Output:

Jan, Feb, Oct, Nov

Example: Numeric Month → Full Month Name

${row.MONTHNUM?date('M')?string('MMMM')}

Sample Output:

January, February, October, November

Notes

These formats can be customized to meet your localization or styling needs using the SimpleDateFormat symbols. Refer to Java’s SimpleDateFormat documentation for the full list of formatting options.

Updated on July 28, 2025

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support