Search code examples
crmmicrosoft-dynamics

Dynamics CRM month query


How can i query a specific month in Dynamics CRM.

            query = new QueryExpression("personnel") { ColumnSet = new ColumnSet("personnelid", "name", "surname", "birthdate") };

            query.Criteria.AddCondition("birthdate", ConditionOperator.ThisMonth);
            result = Portal.Value.Connection.Value.Service.RetrieveMultiple(query);

This returns only if the birthdate's year is current year.


Solution

  • you could use a range to specify the month you want

     query.Criteria.AddCondition("birthdate", ConditionOperator.GreaterEqual, new DateTime(2016,5,1));
     query.Criteria.AddCondition("birthdate", ConditionOperator.LessEqual, new DateTime(2016, 5, 31,23,59,59));
    

    hope it helps