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

Hello @chatsaurav19 

 

Use this :-

 

 

 

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

 

 

 

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

 

Regards,

Samaksh

Says 'Undefined'

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

 

Hi @Samaksh Wani Thank you! It worked!

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