I have the following line of code that pulls a list field date and stores it in a variable called dueDate:
var dueDate = new Date(ctx.CurrentItem.ReminderDate);
How do I create another variable or set the existing one plus 15 days?
I have the following line of code that pulls a list field date and stores it in a variable called dueDate:
var dueDate = new Date(ctx.CurrentItem.ReminderDate);
How do I create another variable or set the existing one plus 15 days?
Dates are calculated in milliseconds (since 1/1/1970)
with
Each day is 1000*60*60*24 = 86400000 milliseconds
to prevent typos and type less characters you can use the scientific notation: 864e5
So to add 15 days, the JavaScript code is:
var dueDate = new Date(ctx.CurrentItem.ReminderDate);
var anotherDate = new Date( dueDate/1 + 864e5*15 );
The important part is dueDate/1 , where a Date value is converted to milliseconds.
Note that this includes the time part of the date notation, 15*24 hours are added.
If you are developing conditional color formatting with CSR,
see: Conditional Formatting Based on Number Range
CSR note: the this scope in a CSR called function references ctx.CurrentItem
so
var dueDate = new Date(ctx.CurrentItem.ReminderDate);
can be written as:
var dueDate = new Date(this.ReminderDate);