Custom Script Converter: What can you do with it?

Adding another converter trick, this time it will help you calculate the number of days between a given date and current day.

In this example, I have dates stored in Excel, formatted as string like this dd/MM/YYYY

image

Then, I’m using this converter on a binding to this date

var date1 = new Date(INPUT);
var date2 = new Date();
var difference = date1.getTime() - date2.getTime();
var days = Math.ceil(difference / (1000 * 3600 * 24));
if (days>0) {
     "Today, it's \n" + days + " days until " + INPUT
} else  {
     "Today, it's \n" + days*(-1) + " days since " + INPUT
}

Final result in Experience

Please note that, according to your locale date format, you may need to tweak your initial date value.
For more, please check Date object javascript documentation.

Cheers.

3 Likes

Linking back another Custom Script Converter usage, converting an HH:mm:ss.sss formatted duration to total seconds

1 Like