Hi All,
I use this Jscript to convert the default field birthdate to text (new_geboortedatumtekst). After upgrading form CRM 2013 to Dynamics 365 on-premise some dates are converted to one day earlyer.
Examples:
1-4-1980 is converted to 31-3-1980. All values in later years are ok.
1-10-1995 is converted to 30-9-1995. All values in later years are ok.
Please help me to fix this!
Thanks in advance.
Jan
function geboortedtekst(ExecutionContext){
Date.prototype.toFormattedString = function(format)
{
var d = this;
var f = "";
f = f + format.replace( /dd|mm|yyyy|MM|hh|ss|ms|APM|\s|\/|\-|,|\./ig ,
function match()
{
switch(arguments[0])
{
case "dd":
var dd = d.getDate();
return (dd < 10)? "0" + dd : dd;
case "mm":
var mm = d.getMonth() + 1;
return (mm < 10)? "0" + mm : mm;
case "yyyy": return d.getFullYear();
case "hh":
var hh = d.getHours();
return (hh < 10)? "0" + hh : hh;
case "MM":
var MM = d.getMinutes();
return (MM < 10)? "0" + MM : MM;
case "ss":
var ss = d.getSeconds();
return (ss < 10)? "0" + ss : ss;
case "ms": return d.getMilliseconds();
case "APM":
var apm = d.getHours();
return (apm < 12)? "AM" : "PM";
default: return arguments[0];
}
});
return f;
}
{
var d = new Date(ExecutionContext.getFormContext().getAttribute("birthdate").getValue());
ExecutionContext.getFormContext().getAttribute("new_geboortedatumtekst").setValue(d.toFormattedString("dd-mm-yyyy"));
}
}