Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

change datetime format

Wade Clairmont
Tera Guru

Lots of posts our there to bring datetime format back to system format, all fine a good, but how can I go the other way,

I need to convert the format from system default format to a custom format

from:  yyyy-mm-dd hh:mm:ss

to: E MMM dd yyyy HH:mm

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

Jaspal Singh
Mega Patron
Mega Patron

Hi Wade,

 

I would use below.

var newDate = 'Monday, June 10, 2020 11:00 AM';
var gdt = new GlideDateTime();

gdt.setDisplayValue(newDate,'E, MMMM dd, yyyy HH:mm');

var dateTimeForField = gdt.getDisplayValue();
gs.print(dateTimeForField);

 

Also, look link that I always prefer for a check.

This is all good, but how would change input 2020-06-08 11:51     

to      Mon, June 8, 2020 11:51