locked
ConditionExpression and dates RRS feed

  • Question

  • Hi There,

    I'm trying to pull some data out of our CRM system, but what I want to do is base it on certain date criteria.

    I have noticed that there is some ConditionOperators around date, but I would like to for instance retrieve Entities that has been created between 2 dates.

    Can anyone point me into the right direction? I have tried the code below, but get an error suggesting date time has to be in a string format. Tried several standard datetime string formats, but now luck.

    ConditionExpression

     

    testCondition3 = new ConditionExpression();

    testCondition3.AttributeName =

    "createdon";

    testCondition3.Operator =

    ConditionOperator.GreaterThan;

     

    var tmpDate = new DateTime(2009, 7, 27, 2, 0, 0);

    testCondition3.Values =

    new string[] { tmpDate.ToString() };


    Thanks,

    Henry

    Monday, July 27, 2009 10:47 PM

Answers

All replies

  • You need to format the DateTime is a particular way. Try:

    testCondition3.Values = new string[] { tmpDate.ToString("yyyy-MM-ddTHH:mm:ssZ") };


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    • Marked as answer by hffourie Thursday, July 30, 2009 10:45 AM
    Tuesday, July 28, 2009 5:03 AM
    Moderator
  • Hi,

    As suggested by David,
    it should be something like this !

       ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "createdon";
                condition1.Operator = ConditionOperator.GreaterThan;
                condition1.Values = new Object[] {
    					"2008-01-02T00:00:00"};
    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Tuesday, July 28, 2009 5:08 AM
  • Hi Guys,

    Thanks for the replies. We've had some internal server issues so was only able to test the suggestions. All works great.

    Regards,

    Henry Fourie
    Thursday, July 30, 2009 10:46 AM