Add 5 days to current date/time gs.nowDateTime()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 11:02 PM
Hi All,
I have an requirement to add some days(5) to current date using BR. please help
Regards,
Jyoti

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 01:41 AM
Try below code:
var gdt = new GlideDateTime();
var date =gdt.getDate();
date.addYears(3);
gs.print(date);
gs.print(gdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 05:23 AM
Just add one more line to your code:
var gd = new GlideDateTime();
gs.print(gd); // Now
gs.print(gd.addYears(3)); // undefined, since addYears hasn't got a return value
gs.print(gd); // in 3 Years, gd is modified
The add... methods do not have a return value, but modify the GlideDateTime Object itself. gd will change it's value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 12:13 AM
Hi,
Please refer below script as it is working .
var date_time =gs.nowDateTime();
var gdt =new GlideDateTime();
gdt.setDisplayValue(date_time );
gs.info(gdt);
gdt.addDays(5);
gs.info(gdt);
Please mark this answer as Correct/Helpful .
Regards,
Manjusha Bangale

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 03:27 AM
Hi Jyoti,
If you are still facing this issue, try the below one.
(function executeRule(current, previous /*null when async*/) {
if(current.retirement_date == ''){
//var gdt = new GlideDate();
var gdt_comp = new GlideDateTime();
var gdt_acc = new GlideDateTime();
var new_date ='';
//Scheduled retirement is 3 years for Computer hardware
if(current.model_category.getDisplayValue() == 'Computer'){
//timeToAdd = 1096;
gdt_comp.addDaysUTC(1096);
new_date = gdt_comp;
gs.log('test----1'+new_date);
}
//Scheduled retirement is 2 years for Accessory hardware
else if(current.model_category.getDisplayValue() == 'Accessory'){
gdt_acc.addDaysUTC(730);
new_date = gdt_acc;
gs.log('test2---'+new_date);
}
current.retirement_date = new_date;
gs.log('test3----'+current.retirement_date);
}
})(current, previous);
Hope this helps!!
Thanks,
Archana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 02:44 PM
I want to use a schedule in script to figure out if they were business days. Can this be done? Thanks