{"id":14637,"date":"2025-07-28T11:33:40","date_gmt":"2025-07-28T16:33:40","guid":{"rendered":"https:\/\/www.mrc-productivity.com\/docs\/?post_type=ht_kb&#038;p=14637"},"modified":"2025-07-28T11:33:41","modified_gmt":"2025-07-28T16:33:41","slug":"date-functions-within-freemarker","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/date-functions-within-freemarker","title":{"rendered":"Date Functions within Freemarker"},"content":{"rendered":"\n<p>Freemarker provides powerful formatting options for working with dates, whether you&#8217;re displaying timestamps, converting numeric values to date formats, or transforming how a date is shown.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Formatting Date Values<\/h2>\n\n\n\n<p>When working with m-Power, it&#8217;s recommended to <strong>first convert your value to a date<\/strong> using <code>?date(...)<\/code> with the correct incoming format. Once the value is treated as a date, you can then format it using <code>?string(...)<\/code>.<\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<p>If your field is stored as a string in <code>yyyyMMdd<\/code> format (e.g., <code>\"20030408\"<\/code>), use the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>${row.ORDERDATE?date(\"yyyyMMdd\")?string[\"MM\/dd\/yyyy\"]}<\/code><\/pre>\n\n\n\n<p><strong>Sample Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>04\/08\/2003<\/code><\/pre>\n\n\n\n<p><strong>SimpleDateFormat Pattern Reference Table<\/strong><\/p>\n\n\n\n<p>Freemarker allows you to use Java\u2019s <code>SimpleDateFormat<\/code> patterns with the <code>?string<\/code> built-in. Below are some common examples:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Pattern<\/th><th>Meaning<\/th><th>Example Output<\/th><\/tr><\/thead><tbody><tr><td><code>y<\/code><\/td><td>Year (e.g., <code>yy<\/code> = 2-digit, <code>yyyy<\/code> = 4-digit)<\/td><td><code>03<\/code>, <code>2003<\/code><\/td><\/tr><tr><td><code>M<\/code><\/td><td>Month (1\u201312)<\/td><td><code>4<\/code><\/td><\/tr><tr><td><code>MM<\/code><\/td><td>Two-digit month (01\u201312)<\/td><td><code>04<\/code><\/td><\/tr><tr><td><code>MMM<\/code><\/td><td>Abbreviated month name<\/td><td><code>Apr<\/code><\/td><\/tr><tr><td><code>MMMM<\/code><\/td><td>Full month name<\/td><td><code>April<\/code><\/td><\/tr><tr><td><code>d<\/code><\/td><td>Day of the month (1\u201331)<\/td><td><code>8<\/code><\/td><\/tr><tr><td><code>dd<\/code><\/td><td>Two-digit day of the month<\/td><td><code>08<\/code><\/td><\/tr><tr><td><code>E<\/code><\/td><td>Abbreviated day of the week<\/td><td><code>Tue<\/code><\/td><\/tr><tr><td><code>EEEE<\/code><\/td><td>Full day of the week<\/td><td><code>Tuesday<\/code><\/td><\/tr><tr><td><code>h<\/code><\/td><td>Hour (1\u201312, no leading zero)<\/td><td><code>9<\/code><\/td><\/tr><tr><td><code>hh<\/code><\/td><td>Hour (1\u201312, two digits)<\/td><td><code>09<\/code><\/td><\/tr><tr><td><code>H<\/code><\/td><td>Hour (0\u201323, no leading zero)<\/td><td><code>21<\/code><\/td><\/tr><tr><td><code>HH<\/code><\/td><td>Hour (0\u201323, two digits)<\/td><td><code>21<\/code><\/td><\/tr><tr><td><code>m<\/code><\/td><td>Minutes (0\u201359)<\/td><td><code>4<\/code><\/td><\/tr><tr><td><code>mm<\/code><\/td><td>Two-digit minutes<\/td><td><code>04<\/code><\/td><\/tr><tr><td><code>s<\/code><\/td><td>Seconds (0\u201359)<\/td><td><code>9<\/code><\/td><\/tr><tr><td><code>ss<\/code><\/td><td>Two-digit seconds<\/td><td><code>09<\/code><\/td><\/tr><tr><td><code>a<\/code><\/td><td>AM\/PM marker<\/td><td><code>PM<\/code><\/td><\/tr><tr><td><code>z<\/code><\/td><td>Time zone abbreviation<\/td><td><code>PDT<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><strong>Tip: <\/strong>You can mix symbols to get exactly the format you need.<\/p>\n\n\n\n<p><strong>Example Usage in Freemarker<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>${row.ORDERDATE?date(\"yyyy-MM-dd\")?string[\"MM\/dd\/yyyy\"]}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>04\/08\/2003<\/code><\/pre>\n\n\n\n<p><strong>Other Examples in Freemarker<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">${row.ORDERDATE?date(\"yyyyMMdd\")?string[\"dd.MM.yyyy, HH:mm\"]}<br>${row.ORDERDATE?date(\"yyyyMMdd\")?string[\"EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'\"]}<br>${row.ORDERDATE?date(\"yyyyMMdd\")?string[\"EEE, MMM d, ''yy\"]}<\/pre>\n\n\n\n<p><strong>Sample Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>08.04.2003, 21:24<br>Tuesday, April 08, 2003, 09:24 PM (PDT)<br>Tue, Apr 8, '03<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Formatting Non-Date Values into Dates<\/h2>\n\n\n\n<p>Sometimes, your data might not be a date value but still represent a date component\u2014like a numeric month (e.g., 1, 2, 10). You can still use Freemarker to display these values as formatted dates.<\/p>\n\n\n\n<p><strong>Example: Numeric Month \u2192 Month Abbreviation<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>${row.MONTHNUM?date('M')?string('MMM')}<\/code><\/pre>\n\n\n\n<p><strong>Sample Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Jan, Feb, Oct, Nov<\/code><\/pre>\n\n\n\n<p><strong>Example: Numeric Month \u2192 Full Month Name<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>${row.MONTHNUM?date('M')?string('MMMM')}<\/code><\/pre>\n\n\n\n<p><strong>Sample Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>January, February, October, November<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Notes<\/h2>\n\n\n\n<p>These formats can be customized to meet your localization or styling needs using the <code>SimpleDateFormat<\/code> symbols. Refer to <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/text\/SimpleDateFormat.html\">Java\u2019s SimpleDateFormat documentation<\/a> for the full list of formatting options.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Freemarker provides powerful formatting options for working with dates, whether you&#8217;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&#8217;s recommended to first convert your value to a date using ?date(&#8230;) with the correct incoming format&#8230;.<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[265],"ht-kb-tag":[],"class_list":["post-14637","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-freemarker"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/14637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/comments?post=14637"}],"version-history":[{"count":2,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/14637\/revisions"}],"predecessor-version":[{"id":14639,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/14637\/revisions\/14639"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/media?parent=14637"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-category?post=14637"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-tag?post=14637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}