Date Difference in Freemarker

I need difference between 2 dates in freemarker. One date is from system while the other date must be hardcoded to 18/02/2021.

Can anyone guide me how to do that because i am facing parsing issues.

My code so far:

 <#assign difference=(record.trandate?long / 86400000)?round - (hardcodedDate?long / 86400000)?round />

record.trandate is the date from system, while hardcodedDate is my entered date.

I tried assigning both below, but didt work:

        <#assign hardcodedDate = "Feb 18, 2021 2:07:30 PM" />
        <#assign hardcodedDate = "Mar 18, 2021 2:07:30 PM" />

In the end, all that is required is difference between the 2 dates.

Answer

hardcodedDateis declared as a String, you have to transform it into a date, using the date built-in.

For example:

<#assign date1 = "Feb 18, 2021 12:07:30 PM"?date("MMMM d, yyyy h:mm:ss a") />
<#assign date2 = "Mar 18, 2021 2:07:30 PM"?date("MMMM d, yyyy h:mm:ss a") />
<#assign difference=(date1?long / 86400000)?round - (date2?long / 86400000)?round />