function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PBS_IC786PBS_IC786 

adding days to date data type

How do I add days to a custom date field in my scontrol?

Already tried...

Test_Date__c = recordset.Sample_date__c ++ 14.0

This does not work...any ideas?
mikefmikef
Good old dates in Javascript. So what I do is create a data object from the value of the date field. Then I add the days to the date object.

This way if you wanted to add 14 days to a date, and lets say the date was 10/22, you wouldn't be passing a date to the api of 2007-10-36 which is invalid. And the date object in JS figures this our for you.

Here is a function you can use to add N number of days to a date.

Code:
function getDateDaysAhead(apiDateField,numDaysAhead){

//seting the string value of numDaysAhead to a number
numDaysAhead = new Number(numDaysAhead);

var startDate = apiDateField.split("-"); //this is in the yyyy-mm-dd format
var year = startDate[0];
var mth = startDate[1];
var day = startDate[2];

var dtNewDate = new Date(year,mth,day);

var dateProposed = new Date(dtNewDate.getFullYear(),dtNewDate.getMonth() -1,dtNewDate.getDate() +numDaysAhead);

//if the Proposed date falls on a Sunday (0) or a Saturday(6), push it out by 2 days
//you can take this out if you are not worried about work week.
if((dateProposed.getDay() == 0) || (dateProposed.getDay() == 6)){
dateProposed = new Date(dtNewDate.getFullYear(),dtNewDate.getMonth() -1,dtNewDate.getDate()+2);
}

return dateProposed;
}


Hope this helps you.