Date format issue in CRM using JavaScript

Sometimes it isn’t easy to deal with Date format and comparing a date in JavaScript in MS Dynamics CRM.
Below is a simple function which takes a UTC date and then return back into a date only in formate YYYYMMDD.
In case you have a string date i.e. not a date then you can cast it into Date by using below
var completedOn = crmForm.formatedDate(completeDate);
// date format
crmForm.formatedDate = function(attr)
var parts = attr.split(/[T]/);
var fullDate= parts[0];
var dt = new Date();
parts = fullDate.split(/[-\/]/);

var y = parts[0];
var m = parseInt(parts[1]);
var d =  parts[2];

var formatedDate =new Date(y  + “/” + m  + “/” + d) ;

return formatedDate;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>