- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 11:27 PM
Hello,
Could some one please help to format date and time in email script?
Current Print format: 2023-07-31 07:00 03
Would like to change to this format: Monday, July 31. 2023 7:00 PM
Here is the email script:
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 09:34 AM
Hi @Radhika11,
For workaround you can try the below scripts,
// var date = "2023-10-31 07:00:03";
// Monday, July 31. 2023 7:00 PM
//
var date = "2023-07-31 11:03:19 PM";
if (new GlideDateTime(date).isValid()) {
var today = new GlideDateTime(date);
gs.info(today);
var day = today.getDayOfMonthUTC();
var month = today.getMonthLocalTime();
var year = today.getYearLocalTime();
var dayofWeek = today.getDayOfWeekLocalTime() % 7;
var time = today.getTime();
var timeCreated = time.getByFormat('HH:mm:ss a');
var Timesplit = timeCreated.split(":");
var strTime = Timesplit[0] + ":" + Timesplit[1] + ":" + Timesplit[2];
// Get the name of the month
var monthList = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var monthName = monthList[month - 1];
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var dayName = weekday[dayofWeek];
// Set the date for the notification
var requiredDate = dayName + ', ' + monthName + ' ' + day + '. ' + year + ' ' + strTime;
gs.info(requiredDate);
} else {
gs.info("not valid date");
}
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 10:34 PM
Hi @Radhika11,
As per my understanding, we have to give date in below string format. It should not contains AM/PM. Then it will be flexible and gives us expected results.
var date = "12-31-2023 11:03:19";
Note: By default GlideDateTime() will take time as 24 hrs.
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 08:49 AM
Good morning @Sagar Pagar
Thank you for continuing providing assistance. User select Date/Time from a Calendar which is Date/Time Type. It will contains AM/PM. It there a workaround to make it show this works?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 09:34 AM
Hi @Radhika11,
For workaround you can try the below scripts,
// var date = "2023-10-31 07:00:03";
// Monday, July 31. 2023 7:00 PM
//
var date = "2023-07-31 11:03:19 PM";
if (new GlideDateTime(date).isValid()) {
var today = new GlideDateTime(date);
gs.info(today);
var day = today.getDayOfMonthUTC();
var month = today.getMonthLocalTime();
var year = today.getYearLocalTime();
var dayofWeek = today.getDayOfWeekLocalTime() % 7;
var time = today.getTime();
var timeCreated = time.getByFormat('HH:mm:ss a');
var Timesplit = timeCreated.split(":");
var strTime = Timesplit[0] + ":" + Timesplit[1] + ":" + Timesplit[2];
// Get the name of the month
var monthList = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var monthName = monthList[month - 1];
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var dayName = weekday[dayofWeek];
// Set the date for the notification
var requiredDate = dayName + ', ' + monthName + ' ' + day + '. ' + year + ' ' + strTime;
gs.info(requiredDate);
} else {
gs.info("not valid date");
}
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 01:33 PM
Hello @Sagar Pagar
It is working the way it should be working.
You are a great helper!
We are sincerely appreciate your time and effort.
Thank you