Add 'n' plus days to a date field in YYYY-MM-DD Format

chatsaurav19
Tera Contributor

Hi All,

 

Can someone please help me to add the logic to add 'n' plus days to a date field and format it to YYYY-MM-DD format?

 

Code:::

---------

 

var date = new Date();
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var lastDayOfMonth = lastDay.getFullYear() + "-" +((lastDay.getMonth()+1).length != 2 ? "0" + (lastDay.getMonth() + 1) : (lastDay.getMonth()+1)) + "-" + lastDay.getDate()

 

var gr1 = new GlideRecord('x_inpe_gbs_inf_gbs_infrastructure_roles');
gr1.query();
while(gr1.next()){
var projectedHireDate = gr1.getDisplayValue('projected_hire_date');
if (projectedHireDate < lastDayOfMonth){
    //projectedHireDate = ( projectedHireDate + 90Days ) into YYYY-MM-DD format
 }
}


Thanks and Regards,
Saurabh Chatterjee
2 ACCEPTED SOLUTIONS

Hello @chatsaurav19 

 

Modify the below line with that script.

 

 

var endDate = gdt.getDate();

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

 

View solution in original post

Hello @chatsaurav19 

 

As per the new rules of Community you can mark Multiple solution as Accept,

 

Can you mark above response as Accept which has the complete script, i have modified that line in original response, by doing so it will help other users to find the solution as well.

 

Thanks,

Samaksh Wani

View solution in original post

9 REPLIES 9

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @chatsaurav19 

Greetings!

you can try addDays

var date = new GlideDateTime(dt);
date.addDays(14);

If my response helped please mark it correct and helpful.

 

Kind Regards,

Ravi Chandra.

Hi @Ravi Chandra_K It did work but I need to remove the Time Format attached ( 00:00:00 ).

 

2023-08-30 00:00:00 

 

Samaksh Wani
Giga Sage
Giga Sage

Hello @chatsaurav19 

 

Add this code in your if Statement

 

 

var gdt = new GlideDateTime(projectedHireDate);
gdt.addDaysLocalTime(7);

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

Hi @Samaksh Wani It also worked but I need to remove the time stamp ( 00:00:00 )

 

2023-08-30 00:00:00