3rd Wednesday of every month as the MailDate
Thu Jan 18 2024 19:02:44 GMT+0000 (Coordinated Universal Time)
Saved by
@montezh2001
//The following Process will create a function that will select the 3rd Wednesday of every month as the MailDate
var currentDate = new Date(new Date().toDateString());
var month = currentDate.getMonth();
var year = currentDate.getFullYear();
//GET FIRST WEDNESDAY OF MONTH AS MAILDATE
function getFirstWednesday (year, month) {
var date = new Date(year, month,1);
var day = date.getDay();
var daysUntilWednesday = (10 - day)%7;
return new Date(year, month, daysUntilWednesday +1);
}
//GET THIRD WEDNESDAY OF MONTH AS MAILDATE
function getThirdWednesday (year, month) {
var date = new Date(year, month, 1);
var day = date.getDay();
var daysUntilThirdWednesday = (3 - day +7)%7 + 14;
return new Date(year, month, daysUntilThirdWednesday + 1);
}
var firstWednesday = getFirstWednesday (year, month);
var thirdWednesday = getThirdWednesday(year, month);
var thirdWednesdayPlusOne = getThirdWednesday(year, month +1);
instance.vars.newMailDate = (currentDate <= firstWednesday) ? thirdWednesday.toLocaleDateString() : thirdWednesdayPlusOne.toLocaleDateString() ;
//USE THE LINE BELOW FOR MANUAL CREATION OF MAIL DATE. COMMENT OUT THE "instance.vars.newMailDate" CODE ABOVE
//instance.vars.newMailDate = new Date("07/19/2023").toLocaleDateString();
logInfo ("Month: " + month);
logInfo ("Year: " + year);
logInfo ("First Wednesday MailDate: " + firstWednesday);
logInfo ("Current Date: " + currentDate);
logInfo ("MailDate: " + instance.vars.newMailDate);
content_copyCOPY
Comments