Formatting DateTime Field in Quick Messages

Utkarsha
Tera Contributor

Hey everyone,

Is there a way we can change the display of glidedatetime type of field in quick messages...I tried using email script but it is not working...mail script is reflecting as it is..I have to display only date by formatting. I am using HTML type of body content.

Any better approach if anyone can suggest,

Getting output in this format: 2024-06-12 14:05:26 IST.

Should be displayed in this format: 2024-06-12

Thank you in advance!

2 REPLIES 2

HrishabhKumar
Kilo Sage

Hi @Utkarsha  ,

You can paste your email script here for reference and debugging. I am providing the code below, your code should look something like this, you can use getByFormat function, assuming they are DateTime or Date format.

var mydateTime = current.date_time_field_name; // add the field name here
var formatedDate = mydateTime.getByFormat("yyyy-MM-dd");
email.body = 'Date is: '+ formatedDate;

 

For using different formats for the date variable you can take a look at this link : https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/GlideDateAPI#Glid...

 

 

Thanks,

Hope this help

 

Jitendra Diwak1
Kilo Sage

Hi @Utkarsha ,

 

Please find the below code:

 

var time = '2024-06-12 14:05:26 IST';
var date = time.split(' ')[0];
gs.info(date +' ');

Here I splitted the string as space then it converted in array so we are now able to get the array position. On zero position, date is placed, 1 position is placed time and 2nd position zone is placed. Hope this will clear if you run this in background script.

 

Please accept my solution if it works for you and thumps up.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.