Please help with date/time format.

Annie10
Tera Contributor

Hello,

Currently, the start date/time format looks like this:

 

Annie10_0-1710364930706.png

I need help on modifying the below script to out put looks like this format:

Example:  03-15-2024  04:24:37 PM

 

Here is the code I used it in Script Background :   THANK YOU

 

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id','89a075671b7cc610925dc910604bcb51');
ritm.query();
if (ritm.next()) {
var dateFieldValue = ritm.variables.select_start_date_and_time;
gs.print('Start Date: '+ dateFieldValue);
}

 

 

 

6 REPLIES 6

Test this code and update at your side.

var gdt = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone('America/New_York');
gdt.setTZ(tz);
gdt.getDisplayValue();
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();

gs.info(gd.getByFormat('dd/M/yyyy') + gt.getByFormat(' HH:mm:ss z'));

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

Annie10
Tera Contributor

Thanks, everyone! I think I've got the code to work:

 

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('sys_id', '89a075671b7cc610925dc910604bcb51');

ritm.query(); if (ritm.next()) {

var dateFieldValue = ritm.variables.select_start_date_and_time.getDisplayValue();

gs.print('Start Date and Time: ' + dateFieldValue);

}

 

Example out put:

Annie10_0-1710369672310.png