locked
Compare CRM date with today RRS feed

  • Question

  • Hi Guys,

    Seems like very simple but I still need your help....

    I want to query database and compare crm date with today. Now database store crmdate as UTC so i wrote following code..

    Please help me to find out what's wrong with this.

    Business logic is, I want all custom entity(new_projects)  where Status == Active and Project end date < today.

    Once i get these collection I want to deactivae those project records.

     Code is as follows...

     

    ColumnSet cols = new ColumnSet();

    cols.Attributes.AddRange(

     

    new string[] { "new_projenddate", "statecode" });

     

     

    ConditionExpression con1 = new ConditionExpression();

    con1.AttributeName =

     

    "statecode";

    con1.Operator =

     

    ConditionOperator.Equal;

    con1.Values =

     

    new string[] { "Active" };

     

     

    ConditionExpression con2 = new ConditionExpression();

    con2.AttributeName =

     

    "new_projenddate";

    con2.Operator =

     

    ConditionOperator.LessThan;

    con2.Values =

     

    new string[] { DateTime.Today.Date.ToUniversalTime().ToString() }; 

     

     

    FilterExpression filter = new FilterExpression();

     

    LogicalOperator.And;

     

     

    QueryExpression query = new QueryExpression();

     

    "new_projects".ToString(); ;

     

    RetrieveMultipleRequest req = new RetrieveMultipleRequest();

     

    true;

     

     

    RetrieveMultipleResponse res = (RetrieveMultipleResponse)service.Execute(req);

     

     

    if (res.BusinessEntityCollection != null && res.BusinessEntityCollection.BusinessEntities.Count > 0)

     

    for (int i = 0; i < res.BusinessEntityCollection.BusinessEntities.Count; i++)

     

    DynamicEntity deproj = (DynamicEntity)res.BusinessEntityCollection.BusinessEntities[i];

    Deactivateproj(deproj[

     

    "new_projectsid"].ToString());

     

     

     

     


    Thank you all for your help - CRM Thirsty

    }

    }

    {

     

    {

     

    req.Query = query;

    req.ReturnDynamicEntities =

    query.Criteria = filter;

     

    query.ColumnSet = cols;

    query.EntityName =

    filter.Conditions.Add(con1);

    filter.Conditions.Add(con2);

    filter.FilterOperator =

    Thursday, October 7, 2010 6:26 AM

Answers

All replies

  • hi instead of datetime of C# use the CrmDateTime which is available in the sdk of it.

     


    yes.sudhanshu

    http://bproud2banindian.blogspot.com
    http://ms-crm-2011-beta.blogspot.com
    • Marked as answer by CRM Thirsty Thursday, October 7, 2010 9:27 AM
    Thursday, October 7, 2010 8:40 AM
  • Here is the code I am using to calculate Number of days between date opportunity was created from today. it is added to the onload event of the form. hope this might give you some hint.

    var currentdate = new Date();

    if (crmForm.all.createdon.DataValue == null)
    {
    crmForm.all.daysoutstanding.DataValue = 0;
    }
    else
    {
    crmForm.all.daysoutstanding.DataValue=Math.round((currentdate -
    crmForm.all.createdon.DataValue)/(86400000));
     }

    Thursday, October 7, 2010 1:12 PM
  • Here is the code I am using to calculate Number of days between date opportunity was created from today. it is added to the onload event of the form. hope this might give you some hint.

    var currentdate = new Date();

    if (crmForm.all.createdon.DataValue == null)
    {
    crmForm.all.daysoutstanding.DataValue = 0;
    }
    else
    {
    crmForm.all.daysoutstanding.DataValue=Math.round((currentdate -
    crmForm.all.createdon.DataValue)/(86400000));
     }

    CRM Thirsty want the date in crm.

    yes.sudhanshu

    http://bproud2banindian.blogspot.com
    http://ms-crm-2011-beta.blogspot.com
    Thursday, October 7, 2010 2:43 PM