Monday, February 18, 2019

SuiteScript> Set a custom date to the nearest one that falls

To set a custom date to the nearest specific day, we can use a script that checks the date today and use that to find the nearest date that falls on that specific day.

Below is a sample function that returns the nearest Date that falls on a Friday.

function getFridayDate(date){

 var fridayDate = new Date();
 day = fridayDate.getDay();

 if (day!=5) {
  var difference = 5 - day;

  if (difference>0){
   fridayDate.setDate(fridayDate.getDate()+(difference + 7));

 return fridayDate.getDate();

No comments:

Post a Comment