Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to specify datetime-type filter

(0) ShareShare
ReportReport
Posted on by
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
    on at
    RE: How to specify datetime-type filter

    Thank you very much. I will try it.

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator 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
    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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans