How change month of date (numerical )to month name and set it in a field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:58 PM
Hi All,
I have a date in format 22/12/2023 , I want to change the month in name, it should be 22/Dec/2023.
Regards,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 11:22 PM
Hi try below code
function onChangeDate() {
var dateField = g_form.getValue('your_date_field'); // Replace 'your_date_field' with the actual field name
// Parse the date string to a JavaScript Date object
var dateObject = new Date(dateField);
// Get the month in three-letter abbreviation
var monthAbbreviation = getMonthAbbreviation(dateObject.getMonth());
// Format the date as DD/Mon/YYYY
var formattedDate = dateObject.getDate() + '/' + monthAbbreviation + '/' + dateObject.getFullYear();
// Set the formatted date back to the field
g_form.setValue('your_date_field', formattedDate);
}
function getMonthAbbreviation(monthIndex) {
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return monthNames[monthIndex];
}