4th Wednesday of every month as the MailDate

PHOTO EMBED

Thu Jan 18 2024 19:03:40 GMT+0000 (Coordinated Universal Time)

Saved by @montezh2001

//The following Process will create a function that will select the 4th Wednesday of every month as the MailDate


var currentDate = new Date();
var month = currentDate.getMonth();
var year = currentDate.getFullYear();

//GET FOURTH WEDNESDAY OF MONTH AS MAILDATE


function getFourthWednesday (year, month) {

var date = new Date(year, month, 1);
var day = date.getDay();
var daysUntilFourthWednesday = (3 - day +7)%7 + 21;

return new Date(year, month, daysUntilFourthWednesday + 1);
}


var fourthWednesday = getFourthWednesday(year, month);

instance.vars.newMailDate = fourthWednesday.toLocaleDateString();

//USE THE BELOW VARIABLE TO ENTER MAIL DATE MANUALLY - COMMENT OUT THE ABOVE instance.vars.newMailDate 

//instance.vars.newMailDate = new Date("12/06/2023");

logInfo ("Current Date: " + currentDate);
logInfo ("MailDate: " + instance.vars.newMailDate);  
//logInfo ("Month: " + month);
//logInfo ("Year: " + year);


content_copyCOPY