
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2022 03:40 PM
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 ??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 10:20 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 09:46 PM
can you share your complete script and mention complete requirement?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 10:01 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 10:20 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2022 10:15 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2022 11:54 AM
this worked very welll. Thankyou Ankur