Add days to datetime field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 09:39 AM
Looking to populate end date with 14 days after the value which is there in the start date (on field change)
Should respect the user date format preference

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 09:57 AM
var gdt = new GlideDateTime(gs.nowDateTime());
task.start_date = gdt;
var ed = new GlideDateTime(gdt);
ed.addDays(14);
task.end_date = ed;
I ran a background script and produced the results you'd expect.
var gdt = new GlideDateTime(gs.nowDateTime());
gs.log(gdt);
var ed = new GlideDateTime(gdt);
ed.addDays(14);
gs.log(ed);
Yes it will respect the user date format preference
Mark the answer as correct and helpful if it helped you..!!!
Regards,
Chalan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 10:00 AM
Hi
Find the below thread which will guide to the solution
https://community.servicenow.com/community?id=community_question&sys_id=8b48cbaddb1cdbc01dcaf3231f961928&view_source=searchResult
Mark it correct/helpful if it helps you.
Regards
Ravindra

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2021 06:49 PM
Hi Neet
Hope you already resolved your query.
Recently I also looked for same answer and I try below script for the date time convert. Hope it will help to others.
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery("user_name=XXX10101");
gr.query();
gs.print("Count:"+gr.getRowCount());
while (gr.next())
{
//Get user birthday date
var ubd = gr.u_date_birthday;
var fixBD = new GlideDateTime(ubd);
fixBD.addDays(14);
//Convert date format date
var gDate = fixBD.getDate();
gDate.getByFormat("yyyy-MM-dd");
gr.u_date_birthday= gDate;
gr.update();
}
Reference link for "GlideDateTime"
https://developer.servicenow.com/print_page.do?release=paris&category=null&identifier=c_APIRef&module=api
Reference link for "getByFormat"
https://developer.servicenow.com/print_page.do?release=paris&category=null&identifier=c_APIRef&module=api