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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans