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)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

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

    Please try ISO 8601 format.

    d1.ToString("s"); 

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    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
    Community Member Profile Picture
    on at

    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
    Community Member Profile Picture
    on at

    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>";
    					


  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Gopalan and Alex

    Thank you so much guys.

    Regards,

    AW

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