Please help with date/time format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 02:27 PM
Hello,
Currently, the start date/time format looks like this:
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 05:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 03:43 PM
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: