locked
how to set CrmDateTime ? RRS feed

  • Question

  • Hi,

    I am getting the following error while assigning the CrmDateTime.

    0x80040265 Object reference not set to an instance of an object. Platform

    Thanks

    Srikanth

     

    Friday, August 13, 2010 9:29 PM

Answers

  • CrmDateTime dateTime = new CrmDateTime();
    dateTime.Value = "2006/5/27T17:00:00";
    Phil Edry – Altriva Solutions – http://www.altriva.com/AltrivaBlog.aspx
    Friday, August 13, 2010 9:44 PM
  • Hi Srikant,

    It seems like you have not retrieved the datetime attribute when you retrieve the entity record. First incluce that column name in the retrieve list of columns. use the below code to assign the datetime value.

    CrmDateTime result = new CrmDateTime();
    result.Value =  "2006/5/27T17:00:00";
    result.IsNull = false;
    result.IsNullSpecified = false;

    // assume patientprofile.eu_date is the entity attribute
    patientprofile.eu_date = result;

    Hope this works.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Saturday, August 14, 2010 3:08 AM

All replies

  • CrmDateTime dateTime = new CrmDateTime();
    dateTime.Value = "2006/5/27T17:00:00";
    Phil Edry – Altriva Solutions – http://www.altriva.com/AltrivaBlog.aspx
    Friday, August 13, 2010 9:44 PM
  • Hi Srikant,

    It seems like you have not retrieved the datetime attribute when you retrieve the entity record. First incluce that column name in the retrieve list of columns. use the below code to assign the datetime value.

    CrmDateTime result = new CrmDateTime();
    result.Value =  "2006/5/27T17:00:00";
    result.IsNull = false;
    result.IsNullSpecified = false;

    // assume patientprofile.eu_date is the entity attribute
    patientprofile.eu_date = result;

    Hope this works.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Saturday, August 14, 2010 3:08 AM
  • Could you paste your code here for enquiry ???
    Mahain : http://mahenderpal.wordpress.com
    Saturday, August 14, 2010 5:00 AM
    Moderator
  • Hi

    If you are setting a dot net datetime to crmdatetime then you should always use dotnetDateTime.ToString(“s”) because crm expects the datetime in ISO 8601 format which formats to something like this "2006/5/27T17:00:00".

    So to set a crmdatetime:

    CrmDateTime newDateTime = new CrmDateTime();
    newDateTime.Value = dotnetDateTime.ToString(“s”);

    It would be easy to answer if you had provided a sample code.

    Thanks,

    Amar

    • Proposed as answer by Faisal Fiaz Saturday, August 14, 2010 8:53 PM
    Saturday, August 14, 2010 7:28 AM