web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve record with date filter Using RestAPI Call

(0) ShareShare
ReportReport
Posted on by 210

Hi Community Team,

I have the custom dateofbirth field in Lead form which I need to used to filter leads  in  CRM Onlinewhich are having the same dateofbirth when creating the new leads.

https://community.dynamics.com/crm/f/117/t/216135

As per referring the above link, I built my javascript code as below get the Date as per OData filter.   

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 = new String();
 DateFilter += date.getUTCFullYear() + "-";
DateFilter += monthString + "-";
DateFilter += dateString;
 DateFilter += "T" + hourString + ":";
 DateFilter += minuteString + ":";
 DateFilter += secondString;
 return DateFilter;
}

var dateofbirth = Xrm.Page.getAttribute("dateofbirth");

var odataDateFormat =getODataUTCDateFilter(dateofbirth.getValue());

alert(odataDateFormat);

When I was alerting the odataDateFormat, I do not get the same value which is entered on the form. see the screenshot below.

Dateissue.PNG

The API call is as below

var context = Xrm.Page.context;

       var serverUrl = context.getClientUrl();

       var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

       var retrieveResult = new XMLHttpRequest();         
      
       retrieveResult.open("GET", ODataPath +"/LeadSet?$select=FullName,LeadId&$filter=(tht_DateOfBirth eq datetime'" + odataDateFormat +"')",false);

 


I do not what I'm doing wrong here. Could anybody help me with data odata data filter issue ?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    The difference that you are getting is Time Zone related.

    The date of birth 24/06/1984 is the same as UTC date 23/06/1984 14:00.

    If you change your source to not use UTC or convert UTC to local time, you should get the same results.

    Hope this helps.

  • Suganthar_Satkunam Profile Picture
    210 on at

    Hi Aric, Thanks for your answer. if I convert UTC to Localtime, how do I use it in Odata filter ? I thought it should be in UTC time format. Please correct me if I'm worng.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans