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 get current date time in this format "Mon, 07 Apr 2025 12:22:54 GMT" ?

robinbkumar
Tera Contributor

how to get current date time in this format "Mon, 07 Apr 2025 12:22:54 GMT" ?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@robinbkumar 

this background script worked for me

var gdt = new GlideDateTime();
var date = gdt.getDisplayValueInternal(); // Get the internal display value

// Format the date and time
var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

var dayOfWeek = days[gdt.getDayOfWeekUTC()];
var day = gdt.getDayOfMonthUTC();
var month = months[gdt.getMonthUTC() - 1]; // getMonthUTC() returns 1-12, so subtract 1 for array index
var year = gdt.getYearUTC();
var time = gdt.getTime().toString().split(' ')[1]; // Extract time part

var formattedDate = dayOfWeek + ', ' + day + ' ' + month + ' ' + year + ' ' + time + ' GMT';

gs.info(formattedDate); // Output the formatted date

Output:

AnkurBawiskar_0-1744044331265.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

Robert H
Mega Sage

Hello @robinbkumar ,

 

Do you need to do this in a client side script or a server side script?

 

For client side you can use:

new Date().toGMTString();

 

For server side you can check some of the other answers.

 

Regards,

Robert