Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to specify datetime-type filter

Posted on by Microsoft Employee
Hello everyone.

I would like to use the following filter with Dynamics CRM select.
---
modifiedon gt 2018-01-02 03:04:05.000+0900
---



However, the following error occurs.
---
Syntax error at position 27 in 'modifiedon gt 2018-01-02 03:04:05.000+0900'.
---

Please tell me if there is a specification method.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to specify datetime-type filter

    Thank you very much. I will try it.

  • Verified answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to specify datetime-type filter

    You can also convert your string to ISO String which should give you the correct results

    var myDate = "2018-01-02 03:04:05.000+0900"; // Not sure where you are getting it from

    var dateString = myDate.toISOString();

    then use:

    var filter = "modifiedon gt " + dateString;

    Try this out...

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to specify datetime-type filter

    If you are using WEB API use the below to format you date and then pass it in filter

    var formatCreatedOn = clientReviewPage.getODataUTCDateFilter(youdatefield)

    filter:      createdon lt " + formatCreatedOn 

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans