- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 04:14 AM
Currently have an email script that:
- Reads closed_at date from associated TASK
- Adds 14 days to that date
- Outputs +14 day value in Email
Issue I am having is with the format. Currently being output in the "dd-MM-yyy HH:mm:ss" format
Is there a way to convert the +14 day value to the desired format "mm-DD-yyyy"
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 04:37 AM
Hi
Please use below script:
var gdt = new GlideDateTime();
gdt.addDaysUTC(14);
var date = gdt.getDate();
var gd = new GlideDate();
gd.setValue(date.toString());
gs.info(gd.getByFormat("dd-MM-yyyy"));
If my answer helped you in any way, please then mark it correct and helpful.
Kind regards,
Manas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 04:34 AM
Hi,
Can you share current script;
you can add 14 days to specific date time as below
var gdt = new GlideDateTime();
gdt.addDaysUTC(14);
gs.print('Output 14 days added is: ' + gdt);
you can pass the closed_at date in the GlideDateTime as below
var gdt = new GlideDateTime(current.closed_at);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
10-23-2019 04:37 AM
Hi
Please use below script:
var gdt = new GlideDateTime();
gdt.addDaysUTC(14);
var date = gdt.getDate();
var gd = new GlideDate();
gd.setValue(date.toString());
gs.info(gd.getByFormat("dd-MM-yyyy"));
If my answer helped you in any way, please then mark it correct and helpful.
Kind regards,
Manas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 04:37 AM
change your format by "MM-dd-yyyy"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 05:36 AM
Thank you!
Was able to adapt this to my current script.
Here is final script
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.addEncodedQuery('encodedquery');
gr.query();
while(gr.next())
{
var closedTask = gr.closed_at.getValue();
var returnDate = new GlideDateTime(closedTask);
returnDate.addDays(14);
var gdt = returnDate.getDate();
var gd = new GlideDate();
gd.setValue(gdt.toString());
template.print(gd.getByFormat("MM-dd-yyyy"));
}