- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 07:36 PM
Hello,
I have an email script that currently print out date and time as "Start Date: 2023-11-19 03:03:15"
Could someone please help to take a look at the blow code to see if it can be print out in this format? Thank you
"Start Date: Saturday, November 19. 2023 at 03:03 AM"
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.document_id.toString());
ritm.query();
if (ritm.next()) {
template.print("Start Date: " + ritm.variables.select_start_date_and_time);
}
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 12:51 AM
Hi @Brian186 ,
I trust you are doing great.
Please find the updated script for the same.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.document_id.toString());
ritm.query();
if (ritm.next()) {
var gdt = new GlideDateTime(ritm.variables.select_start_date_and_time);
var formattedDate = gdt.getDisplayValueInternal(); // Gets the date in system format
// Now format the date as per your requirement
var userFormattedDate = formatDateToUserReadable(formattedDate);
template.print("Start Date: " + userFormattedDate);
}
})(current, template, email, email_action, event);
function formatDateToUserReadable(dateStr) {
var gdt = new GlideDateTime(dateStr);
var day = gdt.getByFormat('EEEE'); // Day in full text
var month = gdt.getByFormat('MMMM'); // Month in full text
var date = gdt.getByFormat('dd'); // Date
var year = gdt.getByFormat('yyyy'); // Year
var time = gdt.getByFormat('hh:mm a'); // Time in 12-hour format with AM/PM
return day + ", " + month + " " + date + ", " + year + " at " + time;
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 10:15 AM
Hi @Brian186
From Amit's comment, you can replace the GlideDateTime by GlideDate, it should do the trick.
Sample
function formatDateToUserReadable(dateStr) {
//var gdt = new GlideDateTime(dateStr);
var gdt = new GlideDate();
gdt.setValue(dateStr);
var day = gdt.getByFormat('EEEE'); // Day in full text
var month = gdt.getByFormat('MMMM'); // Month in full text
var date = gdt.getByFormat('dd'); // Date
var year = gdt.getByFormat('yyyy'); // Year
var time = gdt.getByFormat('hh:mm a'); // Time in 12-hour format with AM/PM
return day + ", " + month + " " + date + ", " + year + " at " + time;
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 10:04 AM
I have also tried your code; however, a 'blank' value was returned
We will do the update soon to make things easier.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 10:15 AM
Hi @Brian186
From Amit's comment, you can replace the GlideDateTime by GlideDate, it should do the trick.
Sample
function formatDateToUserReadable(dateStr) {
//var gdt = new GlideDateTime(dateStr);
var gdt = new GlideDate();
gdt.setValue(dateStr);
var day = gdt.getByFormat('EEEE'); // Day in full text
var month = gdt.getByFormat('MMMM'); // Month in full text
var date = gdt.getByFormat('dd'); // Date
var year = gdt.getByFormat('yyyy'); // Year
var time = gdt.getByFormat('hh:mm a'); // Time in 12-hour format with AM/PM
return day + ", " + month + " " + date + ", " + year + " at " + time;
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 10:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 10:00 AM
Hi @Amit Gujarathi ,
I have tried your suggestion code and we are getting "undefined" value.
We will do the update soon to make things easier.
Thank you