Substract days using GlideSchedule

Poonam Mahajan
Tera Contributor

Hi All, 

 

We have requirement to substract 3 working days from particular date (Maturity date) and add the validations based on newly calculated date.

Can anyone please assist how to use GlideSchedule to substract from Maturity date or is there any other method to achieve this.

 

Thanks 

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

HI @Poonam Mahajan ,
I trust you are doing great.
Here's an example of how you can achieve this using GlideSchedule:

 

// Assuming the Maturity date is stored in a variable called 'maturityDate'
var maturityDate = new GlideDateTime('2023-05-31 00:00:00'); // Replace with your actual Maturity date

// Create a GlideSchedule object to represent the working schedule
var schedule = new GlideSchedule();

// Subtract 3 working days from the Maturity date
var newDate = schedule.durationAfter(maturityDate, -3); // Subtract 3 working days

// Perform your validations based on the newly calculated date
if (newDate) {
  // Validation logic goes here
  gs.info('New calculated date: ' + newDate);
} else {
  gs.error('Failed to calculate the new date.');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi @Amit Gujarathi  : 

 

Thanks you for your response.

I tried above code snippet, but its giving me this error 

Script: Failed to calculate the new date.: no thrown error

Could you please assist. 

Thanks