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

J Siva
Tera Sage

Hi @robinbkumar 

Below are the currently available OOB formats.

Screenshot_20250407-210348.png

 

Regards,

Siva

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

@robinbkumar 

Hope you are doing good.

Did my reply answer your question?

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

@robinbkumar 

I believe you should mark this response as correct so that it helps future members

AnkurBawiskar_0-1744084694747.png

 

 

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