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.

How to Change Date Time format from 02-09-2024 14:30:20 to 02-Sep-2024 02:30 PM

Dasari Srihari
Tera Contributor

Hi All,

 

I need to change date time format from 02-09-2024 14:30:20 to 02-Sep-2024 02:30 PM as a info message , but i'm getting error message as undefended

 

Background Script:

var date = new GlideDateTime();
var date2 = date.getByFormat('dd-MMM-yyyy hh:mm a');
gs.print(date2); 

 

Error: undefined

 

Can someone please help me on this

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try this

 

var gdt = new GlideDateTime();
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();

var fd = gd.getByFormat('dd-MMM-yyy') + gt.getByFormat(' HH:mm a');
gs.print(fd)
-Anurag

View solution in original post

1 REPLY 1

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try this

 

var gdt = new GlideDateTime();
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();

var fd = gd.getByFormat('dd-MMM-yyy') + gt.getByFormat(' HH:mm a');
gs.print(fd)
-Anurag