How to obtain the next day from the current date in the business rule?

shiz
Tera Contributor

shiz_0-1732158502369.png

 

2 ACCEPTED SOLUTIONS

Ashish Parab
Mega Sage

Hello @shiz ,

 

Try below code:

 

function executeRule(current, previous /*null when async*/) {

    // Extract the current date
    var actualTimeDetailsRecord = new Date(current.u_week_starts_on);

    // Calculate dates for each day of the week
    var mondayDate = new Date(actualTimeDetailsRecord); // Start date (Monday)
    var tuesdayDate = new Date(actualTimeDetailsRecord);
    tuesdayDate.setDate(tuesdayDate.getDate() + 1); // Add 1 day for Tuesday

    // To calculate a date 7 days after the start date
    var sevenDaysLater = new Date(actualTimeDetailsRecord);
    sevenDaysLater.setDate(sevenDaysLater.getDate() + 7); // Add 7 days

    // Output the dates
    gs.info('Monday Date: ' , mondayDate);
    gs.info('Tuesday Date: ' , tuesdayDate);
    gs.info('7 Days Later: ' , sevenDaysLater);
}

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

 

View solution in original post

Community Alums
Not applicable

In this example, replace yourDateField with the actual field name where you want to set the next day's date.

This script gets the current date and time, adds one day to it, and then sets the result to the specified field.

 

(function executeRule(current, previous) {
var currentDate = new GlideDateTime(gs.nowDateTime());
currentDate.addDays(1);
current.yourDateField = currentDate.getDisplayValue();
})(current, previous);

View solution in original post

4 REPLIES 4

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @shiz 

 

Try 

var TomorrowDate = new GlideDate();

//Add number depending on your requirement 

  TomorrowDate.addDaysLocalTime(1);

 gs.addInfoMessage("Date is: " + TomorrowDate)

 

Please mark the answer as helpful and correct if helped

 

Kind Regards,

Ravi Chandra 

Ashish Parab
Mega Sage

Hello @shiz ,

 

Try below code:

 

function executeRule(current, previous /*null when async*/) {

    // Extract the current date
    var actualTimeDetailsRecord = new Date(current.u_week_starts_on);

    // Calculate dates for each day of the week
    var mondayDate = new Date(actualTimeDetailsRecord); // Start date (Monday)
    var tuesdayDate = new Date(actualTimeDetailsRecord);
    tuesdayDate.setDate(tuesdayDate.getDate() + 1); // Add 1 day for Tuesday

    // To calculate a date 7 days after the start date
    var sevenDaysLater = new Date(actualTimeDetailsRecord);
    sevenDaysLater.setDate(sevenDaysLater.getDate() + 7); // Add 7 days

    // Output the dates
    gs.info('Monday Date: ' , mondayDate);
    gs.info('Tuesday Date: ' , tuesdayDate);
    gs.info('7 Days Later: ' , sevenDaysLater);
}

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

 

Community Alums
Not applicable

In this example, replace yourDateField with the actual field name where you want to set the next day's date.

This script gets the current date and time, adds one day to it, and then sets the result to the specified field.

 

(function executeRule(current, previous) {
var currentDate = new GlideDateTime(gs.nowDateTime());
currentDate.addDays(1);
current.yourDateField = currentDate.getDisplayValue();
})(current, previous);

Juhi Poddar
Kilo Patron

Hello @shiz 

Please refer the below script:

(function executeRule(current, previous) {
    var gdtCurrentDate = new GlideDateTime();
    gdtCurrentDate.addDays(7); //Add 7 day from today local date
    gs.info("Date 7 days from today" + gdtCurrentDate);
})(current, previous);

Hope this helps!

 

"If you found my answer helpful, please  like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar