Email Script - Date Format

JonMS
Tera Expert

Currently have an email script that:

  1. Reads closed_at date from associated TASK
  2. Adds 14 days to that date
  3. 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"
1 ACCEPTED SOLUTION

Manas Kandekar
Kilo Guru

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Manas Kandekar
Kilo Guru

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

change your format by "MM-dd-yyyy"

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"));
	}