- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 12:04 AM
Hello All,
I am adding 14 days to current date type filed and setting into date type field?
I have written below code for adding 14 days to current date and adding into date type variable as below
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('Request_AjaxUtil');
ga.addParam('sysparm_name', 'setNeedByDate');
ga.getXML(setDate);
function setDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("need_by_date", answer);
}
}
Script Include Function
setNeedByDate: function() {
var currentDate = new GlideDateTime();
currentDate.addDaysLocalTime(14);
gs.addInfoMessage("14 days " + currentDate.getDate());
return currentDate.getDate();
},
Output : "2020-02-13" (today's output) but I want change this format to "13-Feb-20"
How can I change this "2020-02-13" format to "13-Feb-20"
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 01:00 AM
you can use below script
Sample code:
var gd = new GlideDate();
gd.setValue('2015-01-01');
gs.info(gd.getByFormat("dd-MMM-yyyy"));
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_ScopedGlideDateGetByFormat_String
script Include:
var currentDate = new GlideDateTime();
currentDate.addDaysLocalTime(14);
gs.print(currentDate.getDate().getByFormat("dd-MMM-yyyy"));
If my answer helped you , kindly mark the answer correct and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 01:00 AM
you can use below script
Sample code:
var gd = new GlideDate();
gd.setValue('2015-01-01');
gs.info(gd.getByFormat("dd-MMM-yyyy"));
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_ScopedGlideDateGetByFormat_String
script Include:
var currentDate = new GlideDateTime();
currentDate.addDaysLocalTime(14);
gs.print(currentDate.getDate().getByFormat("dd-MMM-yyyy"));
If my answer helped you , kindly mark the answer correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 03:30 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 01:17 AM
Hi,
You can also set default value to date field by adding days.Check below link it will help you.
Mark correct/helpful based on impact.
Thanks,
Dhananjay.