Get Date Part from Sqldate

Most of the time we need to set datatime field value in crm, but problem is that ms crm datetime file format is different from sql server date format so i have written a some js to get date part from sqlserver datetime field.
we can pass datetime value to this function and it will return date part from datetime value.
function GetDate(strCrmFormatDate)
{
var newDate=new Date();
var indexofT=strCrmFormatDate.indexOf(“T”);
var strdatepart=strCrmFormatDate.substring(0,indexofT);
var month=strdatepart.substring(5,7);
var year=strdatepart.substring(0,4);
var day=strdatepart.substring(8);
if(month.substring(0,1)==’0′)
{
month=month.substring(1);
}

newDate.setMonth(parseInt(month)-1);
newDate.setFullYear(year);
newDate.setDate(day);
return newDate;
}

Leave a Reply

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