Dynamics CRM DateTime format filter in web API:
function getODataUTCDateFilter(date) { var monthString; var rawMonth = (date.getUTCMonth() + 1).toString(); if (rawMonth.length == 1) { monthString = "0" + rawMonth; } else { monthString = rawMonth; } var dateString; var rawDate = date.getUTCDate().toString(); if (rawDate.length == 1) { dateString = "0" + rawDate; } else { dateString = rawDate; } var hourString = date.getUTCHours().toString(); if (hourString.length == 1) hourString = "0" + hourString; var minuteString = date.getUTCMinutes().toString(); if (minuteString.length == 1) minuteString = "0" + minuteString; var secondString = date.getUTCSeconds().toString(); if (secondString.length == 1) secondString = "0" + secondString; var DateFilter = "datetime'"; DateFilter += date.getUTCFullYear() + "-"; DateFilter += monthString + "-"; DateFilter += dateString; DateFilter += "T" + hourString + ":"; DateFilter += minuteString + ":"; DateFilter += secondString + "Z'"; return DateFilter; }
There was a small error in this line DateFilter += secondString + "Z'";
ReplyDeleteWorking code DateFilter += secondString + "Z";//Removed the apstrohe