locked
DateTime to CRM Datetime - day behind when updated to CRM RRS feed

  • Question

  • Hi,

    When updating a DateTime value to CRM Datetime value the day is behind by one day sometimes. I can't seem to nail exactly what to reproduce this issue.
    I have read that this is because of settings in CRM needs to be set correctly to the machine time. I have ensured that the setting is GMT but it is still incorrect.

    This is what I'm doing in the conversion method:

    //CRM expects DateTime to be submitted as UTC

     

    DateTime utcValue = value.ToUniversalTime();

     

     

    CrmDateTime convertedValue = new CrmDateTime(); "yyyy-MM-ddTHH:mm:ss");

    Thanks!

    convertedValue.Value = utcValue.ToString();

    ----------------------------------
    This is the value passed: {12/11/2010 12:00:00 AM}

    This is the converted value: {12/11/2010 8:00:00 AM}

    ---------------------------------
    The above should be identical shouldn't it?

    Or should I force the conversion to the format:
    convertedValue.Value = utcValue.ToString(

    • Edited by GreenWasabi Friday, September 25, 2009 1:09 PM typo
    Friday, September 25, 2009 12:58 PM

Answers

  • Hi,

    to convert a UTC-Time to local CRM time, I use this 

    DateTime.Pase(((CrmDate)Entity.Properties["new_WorkDate"]).value).ToLocalTime();

    I think, you have to do the same thing to observe the timezone settings
    Viele Grüße

    Michael Sulz
    axcentro GmbH
    MVP für Microsoft Dynamics CRM
    Friday, September 25, 2009 1:46 PM

All replies

  • Hi,

    to convert a UTC-Time to local CRM time, I use this 

    DateTime.Pase(((CrmDate)Entity.Properties["new_WorkDate"]).value).ToLocalTime();

    I think, you have to do the same thing to observe the timezone settings
    Viele Grüße

    Michael Sulz
    axcentro GmbH
    MVP für Microsoft Dynamics CRM
    Friday, September 25, 2009 1:46 PM
  • Hi,

    I don't know wether I miss something, but why you don't use

    DateTime utcValue = value.ToUniversalTime(); 
    
    CrmDateTime crmDate = CrmDateTime.FromUniversal(utcValue);
    or

    CrmDateTime crmDate = CrmDateTime.FromUser(value);
    In order to show the date in the users timezone, you could use the property UserTime of the CrmDateTime-class

    Friday, September 25, 2009 2:27 PM