The Now Platform® Washington DC release is live. Watch now!
07-06-2017 08:11 AM
Hi,
I have written some Validation to the Date Field , i.e, The Date field should be filled by default on "Onload" with some specific Date.
Everything is working fine except the Date Format. OnLoad the Date format is "YYYY_MM_DD" but on selection of any date, the format is different "DD_MM_YYYY".
I want the default Date format in "DD_MM_YYYY", how to set that , Can anyone please help me out.
Thanks in Advance.
BR.
Smitha
Solved! Go to Solution.
07-06-2017 08:59 AM
Since GlideDate() as well as GlideDateTime() always use yyyy-mm-dd, you can change the format of your return value of dat by just adding .getDisplayValue():
return dat.getDisplayValue();
That will give you the format of whatever the user has even if they are using something else such as mm-dd-yyyy
07-06-2017 08:14 AM
Are you populating your date field via script, or by a default value on the dictionary? Knowing how the date is set should assist in how we can answer your question.
07-06-2017 08:31 AM
Yes, I am populating the Date via script. Find the below snippet:
Script Include:
var getdate = Class.create();
getdate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdatevalue : function()
{
var dat = new GlideDate();
dat.addDaysUTC(5);
return dat;
},
type: 'getdate'
});
client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('getdate');
ga.addParam('sysparm_name','getdatevalue5');
ga.getXML(callback);
}
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('end_date',answer);
}
07-06-2017 08:59 AM
Since GlideDate() as well as GlideDateTime() always use yyyy-mm-dd, you can change the format of your return value of dat by just adding .getDisplayValue():
return dat.getDisplayValue();
That will give you the format of whatever the user has even if they are using something else such as mm-dd-yyyy
07-06-2017 09:22 AM
So basically dat.getDisplayValue() will return default or if set in user preferences, user preferred date format?
Sweet.