Mismatch or misconfiguration in the date formatting logic in NetSuite Advanced PDF/HTML Template can occur due to various reasons.
First reason can be because the date value maybe passed as a string which causes error in formatting.
Secondly, for some formats, the Julian day maybe calculated instead of the day of the month or other issues related to the format which causes improper calculation of the month.
When the date format is “DD/MM/YYYY”, first convert it to the “dd/MM/yyyy” which provides the correct result.
Normally, ?date can be used to format a string to the correct date format.
<#assign currentDate = .now>
.now is used to get the current date and time.
${currentDate?date}
This converts the currentDate to correct date format.
For converting date to a particular format,
<#assign dateFormat = DateFormatLogic>
<#assign recDate = record.date>
${recDate?string(dateFormat)}
The DateFormatLogic can be fetched through script.
In the script, if the format is DD/MM/YYYY, we need to convert it to dd/MM/yyyy with the help of following code snippet.
let date1 = “DD/MM/YYYY”;
let date2= date1.replace(“DD”,”dd”);
let DateFormatLogic = date2.replace(“YYYY”,”yyyy”);
Keeping MM uppercase for the month and dd and yyyy lowercase can ensure correct interpretation and formatting.