Please help with formatting date and time in notification on sc_req_item table

Radhika11
Tera Contributor

Hello everyone,

We have been trying to formatting date and time variable on the sc_req_item table, but we are having a difficult time getting it to work.  We are on Tokyo version.  Please help.  Thank you

 

format from "Purchased Date: 12-15-2023 02:24:04 PM PST" 

to "Purchased Date: Friday, December 15. 2023 02:24 PM

 

Currently Notification: 

 

Radhika11_0-1702680391896.png

 

Currently Output:

Description: Test

Purchased Date: 12-30-2023 02:24:04 PM PST

 

 

 

2 REPLIES 2

AshishKM
Kilo Patron
Kilo Patron

Hi @Radhika11,

Please share the formatting part from mail script.

You have to get Day, Month and Day from date object and them print together.

 

Try the below code in backgroup script and adjust the same in mail script

var gDate = new GlideDateTime().getDate();
var newDate = gDate.getByFormat('EEEE, MMMM dd HH:mm:ss a z');
//gs.print(gDate.getByFormat('EEEE, MMMM dd HH:mm:ss a z'));
gs.print(newDate);

The output of this code

AshishKMishra_0-1702683589704.png

 

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

BalaG
Kilo Sage

Hello @Radhika11 

here is the javascript that generates date time in the format you need.

var gd = new GlideDate(); 
gd.setValue('2021-04-21 22:12:55'); 
gs.log(gd.getByFormat("EEEE, LLLL dd, yyyy hh:mm a"));
// output:  Wednesday, April 21, 2021 10:12 PM

Please see the following SN and JAVA APIs for more details.

 

https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server_legacy/GlideDateAPI#GlideDa...

 

https://docs.oracle.com/javase/10/docs/api/java/text/SimpleDateFormat.html

 

hope this helped

--

Bala Guthy

 

Please mark this as helpful or a solution as appropriate.