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)

Custom filter and Date Field

(0) ShareShare
ReportReport
Posted on by

Hello,

I have a problem with my JavaScript. I try to add a custom filter on a field but i have an error with Date format.

My date is "Fri Apr 10 00:00:00 UTC+0200 2015" but when i use this date in my fetchxml, i get this error:

"The date-time format for Fri Apr 10 00:00:00 UTC+0200 2015 is invalid, or value is outside the supported range."

My JavaScript is :

	var d = new Date();
	var DateJour=new Date(d.getFullYear(),d.getMonth(),d.getDate(), 0, 0, 0, 0);

	Xrm.Page.getControl("productid").addPreSearch(function () {
fetchXml = "<filter type='and'><condition attribute='new_date' operator='ge' value='" + DateJour + "' /></filter>";
Xrm.Page.getControl("productid").addCustomFilter(fetchXml);});


 What format should I use ?

Thank-you very much for your help.

Best regards,

Florian



*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    you need to pass date string in the format of YYYY-MM-DDTHH:MM:SS

    for example  10th April 2015 can be passed like below in US eastern TIme

    2015-04-10T05:00:00

    You could use below script to convert to right format

    function toODataUTC(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 DateFilter = "";//"datetime\'";

              DateFilter += date.getUTCFullYear() + "-";

              DateFilter += monthString + "-";

              DateFilter += dateString;

              DateFilter += "T" + (date.getUTCHours() < 10 ? "0" + date.getUTCHours() : date.getUTCHours()) + ":";

              DateFilter += (date.getUTCMinutes() < 10 ? "0" + date.getUTCMinutes() : date.getUTCMinutes()) + ":";

              DateFilter += (date.getUTCSeconds() < 10 ? "0" + date.getUTCSeconds() : date.getUTCSeconds()); //+ ".";

              //DateFilter += (date.getUTCMilliseconds() < 10 ? "0" + date.getUTCMilliseconds() : date.getUTCMilliseconds());

              // DateFilter += "0Z\'";

              return DateFilter;

          }

  • Suggested answer
    Community Member Profile Picture
    on at

    I believe they have to be in the format "yyyy-MM-dd hh:mm:ss"

    function formatDate(d){

     function addZero(n){

        return n < 10 ? '0' + n : '' + n;

     }

       return addZero(d.getMonth()+1)+"/"+ addZero(d.getDate()) + "/" + d.getFullYear() + " " +

              addZero(d.getHours()) + ":" + addZero(d.getMinutes()) + ":" + addZero(d.getMinutes());

    }

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Florian,

    I think you should use the “yyyy-MM-dd” format

    unleashingcrm.wordpress.com/.../filtering-date-field-in-the-filtered-lookup

    www.crmanswers.net/.../on-or-before-and-on-or-after-conditions.html

    try to change your code accordingly

    var d = new Date();

    var DateJour=new Date(d.getFullYear(),d.getMonth(),d.getDate(), 0, 0, 0, 0);

    var frmatedDateJour = DateJour.format(“yyyy-MM-dd”);

    If can't make it then the second line change to this:

    var DateJour= new Date(d.setDate(d.getDate()));

    Hope this helps.

    Thanks.

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