Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

The date-time format for createdon is invalid, or value is outside the supported range

Posted on by Microsoft Employee

I want to retrieve all records based on recent  similar createdon date. It is showing following exception.

The date-time format for createdon is invalid, or value is outside the supported range

Query:

 

var d1 = Convert.ToDateTime(subaction["startdate"]);

 var d2 = Convert.ToDateTime(subaction["approvedenddate"]);

 string FetchXML = "<fetch>" +

                    "  <entity name=\"sales\" >" +

                    "    <attribute name=\"rate\" />" +

                    "    <filter type=\"and\">" +

                    "      <condition attribute=\"date\" operator=\"between\" descending=\"true\" >" +

                    "      <value> " + d1.ToString("MM/dd/yyyy") + " </value>" +

                    "      <value> " + d2.ToString("MM/dd/yyyy") + " </value>" +

                    "      </condition>" +

                    "       <condition attribute=\"createdon\"  operator=\"eq\" value=\"createdon\" >" +

                    "      </condition>" +

                    "         <condition attribute=\"ford_approved\" operator=\"eq\" value=\"1\" />" +

                    "    </filter>" +

                    "      <order attribute=\"createdon\" descending=\"true\" />" +

                    "  </entity>" +

                    " </fetch>";

 

Please help me with this issue.

*This post is locked for comments

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: The date-time format for createdon is invalid, or value is outside the supported range

    Hi Gopalan and Alex

    Thank you so much guys.

    Regards,

    AW

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: The date-time format for createdon is invalid, or value is outside the supported range

    Use below function to format your date to yyyy-mm-dd:

    					function formatDate(date) {
        var d = new Date(date),
            month = '' + (d.getMonth() + 1),
            day = '' + d.getDate(),
            year = d.getFullYear();
    
        if (month.length < 2) month = '0' + month;
        if (day.length < 2) day = '0' + day;
    
        return [year, month, day].join('-');
    }

    var d1 = Convert.ToDateTime(subaction["startdate"]);
     var d2 = Convert.ToDateTime(subaction["approvedenddate"]);
     
     d1 = formatDate(d1);
     d2 = formatDate(d2);
     
     string FetchXML = "<fetch>" +
                        "  <entity name=\"sales\" >" +
                        "    <attribute name=\"rate\" />" +
                        "    <filter type=\"and\">" +
                        "      <condition attribute=\"date\" operator=\"between\" descending=\"true\" >" +
                        "      <value> " + d1 + " </value>" +
                        "      <value> " + d2 + " </value>" +
                        "      </condition>" +
                        "       <condition attribute=\"createdon\"  operator=\"eq\" value=\"createdon\" >" +
                        "      </condition>" +
                        "         <condition attribute=\"ford_approved\" operator=\"eq\" value=\"1\" />" +
                        "    </filter>" +
                        "      <order attribute=\"createdon\" descending=\"true\" />" +
                        "  </entity>" +
                        " </fetch>";
    					


  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: The date-time format for createdon is invalid, or value is outside the supported range

    Hi Priyanka,

    Value should be date in "yyyy-MM-dd" format for "createdon" condition.

    and one more thing, Please use "on" operator instead of "eq" for date.

    For Example, you can use

    <condition attribute="createdon" value="2017-05-19" operator="on"/>

    Hope this helps

    Thanks & Regards

    Himanshu Prajapati

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: The date-time format for createdon is invalid, or value is outside the supported range

    I don't think there it toISOString in c#?

    Pretty sure that date format depends on how user settings are configured.. so, if the plugin/workflow is running in the context of a specific user, the date format used for those fetch conditions has to match the date format configured for that user in CRM.

    You might try using the approach described here to get user-specific date format from CRM:

    bds-experts.com/get-user-personal-settings

    And, then, may have to use that format for the data conversions.

    Or you might just convert that fetch into a queryexpression - you can use DateTime parameters without "ToString" conversion there:

    stackoverflow.com/.../how-to-write-a-between-query-expression-for-todays-date-and-two-date-attribut

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: The date-time format for createdon is invalid, or value is outside the supported range

    Hi

    Alex is correct, ((Sorry, I provided for JS).

    Please try ISO 8601 format.

    d1.ToString("s"); 

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