I want to Change the Date format from YYYY/MM/DD To MM/DD/YYYY on Catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:12 PM
HI There,
On Catalog Item form Now I have date variable format is YYYY/MM/DD to MM/DD/YYYY
Can anyone please help me how to get the solution for this.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:22 PM - edited 12-20-2023 10:23 PM
Hi @Community Alums
This display format is governed by the user preferences/system default.
As far as I know, there is no attribute where we can change the data format.
If you want to convert this value to a different format for your backend processing, we can do that.
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:39 PM
Hello @Community Alums ,
Please refer the link below and let me know how it works for you.
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 04:51 AM
I have used the Script Include that you have mentioned to someone's question, for setting the Date Format,
var MyConversion = Class.create(); MyConversion.prototype = { initialize: function() { }, convertDateFormat: function(){ var incomingDate = this.getParameter('sysparm_format') + ' 00:00:00'; var format = 'yyyy/dd/MM HH:mm:ss'; var gdt = new GlideDateTime(); gdt.setDisplayValue(incomingDate,format); var gd = new GlideDate(); gd.setValue(gdt.getDate()); return gd.getByFormat("MM/dd/yyyy"); }, type: 'MyConversion' };
Could you please help me with the Onchange Client script, for getting the date format.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 05:07 AM
Hello @Community Alums ,
Please give a try to the below script once and let me know how it works for you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
var dateField = g_form.getControl('your_date_variable'); // Replace 'your_date_variable' with the actual variable name
var currentDate = dateField.value;
if (currentDate) {
var formattedDate = convertDateFormat(currentDate); // Call your date conversion function
dateField.value = formattedDate;
}
}
function convertDateFormat(incomingDate) {
// Your date conversion logic here
// You can use the same logic as in your Script Include
// Example:
var gdt = new GlideDateTime();
gdt.setDisplayValue(incomingDate + ' 00:00:00');
var gd = new GlideDate();
gd.setValue(gdt.getDate());
return gd.getByFormat("MM/dd/yyyy");
}