OL Learn

Subtract 8 days from date

I have a date field that I need to remove 8 days from. How do I add the calculation to remove 8 days from my below code? Obviously, it would need to take into account the different lengths (number of days) in any given month etc

var field, result = “”;

field = record.fields[“Date”];
if (field !== “”) result += formatter.dateLong(field);


Hi marrd,

Did a little research and played around a bit. I think this does it.

//My mapper field OriginalDate, set as Date in mapper, formatted to dd/mm/yyyy.
var myDate = record.fields.OriginalDate;
//Minus 8 days, returns milliseconds.
var newDate = myDate.setDate(myDate.getDate() - 8);
//Convert milliseconds into date.
var date = new Date(newDate);

//Return result, format date as long date.