Add 3 days to current date scoped app

Dhez Vu
Tera Expert

Hi, 

Anyone help me with the below scenario: 

I'm trying to add 3 days if the current system time is above 3 PM. Tried addDays and it's not working in the scoped application. 

Any suggestions ??

 

1 ACCEPTED SOLUTION

Hi,

something like this

var myDate = new GlideDateTime('<your date>');

var gdt = new GlideDateTime();
var time = gdt.toString().split(' ')[1];

var hour = time.split(':')[0];

hour = parseInt(hour);

if(hour > 15){
	myDate.addDaysUTC(3);
}

// now use myDate to set the value

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

can you share your complete script and mention complete requirement?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Dhez Vu
Tera Expert

complete requirement : 

1. I'm setting the date to one field.  and it needs to check if the current system time is greater than 3PM then that we need to add 3 days to the field. If the current system time is below 3PM then the date field should populate the current date. 

Hi,

something like this

var myDate = new GlideDateTime('<your date>');

var gdt = new GlideDateTime();
var time = gdt.toString().split(' ')[1];

var hour = time.split(':')[0];

hour = parseInt(hour);

if(hour > 15){
	myDate.addDaysUTC(3);
}

// now use myDate to set the value

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Dhez Vu
Tera Expert

thankyou for your prompt reply Ankur. This worked very well. 

One last additional que is: if I want to change the final output date format to 'MMddyy' I used getFormat() function and it's throwing an error as this function is not available in the object. 

 

myDate should be in format of "MMddyy" format 

Dhez Vu
Tera Expert

this worked very welll. Thankyou Ankur