Date Manipulation with the addWeekToDate Function in FreeMarker

To simplify this process, a custom function called addWeekToDate can be implemented. This article will explore the addWeekToDate function, its implementation, and its usage within an EFT template.

Understanding the addWeekToDate Function: The addWeekToDate function takes an input date and returns a new date that is one week ahead. Let’s break down the implementation step by step:

<#function addWeekToDate inputDate>
    <#assign datestr = inputDate?date?string("yyyy/MM/dd")>
    <#assign dateObj = datestr?date("yyyy/MM/dd")>
    <#assign milliseconds = dateObj?long + (7 * 24 * 60 * 60 * 1000)>
    <#return milliseconds?number_to_datetime?string("yyDDD")>
</#function>

Using the addWeekToDate Function in an EFT Template: Once the addWeekToDate function is defined, it can be utilized within an EFT template to perform date calculations.

<#assign startDate = “2023/05/01”?date>
<#assign newDate = addWeekToDate(startDate)>
The new date is ${newDate}.

Leave a comment

Your email address will not be published. Required fields are marked *