Search This Blog

Wednesday, July 12, 2017

Dynamics CRM DateTime format filter in web API

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;
}

1 comment:

  1. There was a small error in this line DateFilter += secondString + "Z'";
    Working code DateFilter += secondString + "Z";//Removed the apstrohe

    ReplyDelete

Note: Only a member of this blog may post a comment.