How to get date difference in advanced pdf template in Netsuite.

To calculate the date difference in an Advanced PDF/HTML template in NetSuite, you can utilize the FreeMarker template language. FreeMarker allows you to perform date manipulations and arithmetic operations directly within your template. Here’s an example demonstrating how to calculate the difference in days between two dates.

First, you need to define your dates. In this example, `date1` is set to “Feb 18, 2021 12:07:30 PM”, and `date2` is set to “Mar 18, 2021 2:07:30 PM”. The dates are parsed using the FreeMarker `?date` built-in function with a specific format.

<#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”) />

Next, calculate the difference between these two dates in milliseconds. This is done by converting each date to a long value using the `?long` built-in function. Then, divide the result by 86400000 (the number of milliseconds in a day) and round the result to get the difference in whole days.

<#assign difference = (date1?long / 86400000)?round – (date2?long / 86400000)?round />

Finally, you can display the calculated difference in your PDF/HTML template:

<p>The difference between ${date1?string(“MMMM d, yyyy h:mm:ss a”)} and ${date2?string(“MMMM d, yyyy h:mm:ss a”)} is ${difference} days.</p>

This approach ensures that the date difference is accurately calculated and displayed in your Advanced PDF/HTML template, providing clear and precise information within your NetSuite documents.

Leave a comment

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