locked
CRM time difference in record RRS feed

  • Question

  • Hi ,

    i am facing some issue with date time field,

    i am trying to retrieve few attribute field value from lead entity. 

    while verifying start date fiel values i could find there is change in time. 

    it display few hours difference between the actual date time given in crm . and the retrieve record.

    I have checked my utc time settings in personal settings area.

    Worst case. i can add few hours and can compensate to the actual hours available in crm.

    But i need to know what is the original cause of this issue.

    is there any proper approach for this to be fixed.

    thanks 

    Sunday, September 28, 2014 1:48 PM

Answers

  • When you retrieve datetime fields from CRM you get the UTC value.

    You just need to do a .ToLocalTime() after.

    DateTime createdOn = entity.GetAttributeValue<DateTime>("createdon");
    createdOn = createdOn.ToLocalTime();


    My blog: www.crmanswers.net - Rockstar 365 Profile


    • Edited by Guido PreiteMVP Sunday, September 28, 2014 3:17 PM
    • Proposed as answer by Guido PreiteMVP Sunday, September 28, 2014 3:19 PM
    • Marked as answer by kMAT1 Thursday, October 9, 2014 8:43 AM
    Sunday, September 28, 2014 3:16 PM

All replies

  • When you retrieve datetime fields from CRM you get the UTC value.

    You just need to do a .ToLocalTime() after.

    DateTime createdOn = entity.GetAttributeValue<DateTime>("createdon");
    createdOn = createdOn.ToLocalTime();


    My blog: www.crmanswers.net - Rockstar 365 Profile


    • Edited by Guido PreiteMVP Sunday, September 28, 2014 3:17 PM
    • Proposed as answer by Guido PreiteMVP Sunday, September 28, 2014 3:19 PM
    • Marked as answer by kMAT1 Thursday, October 9, 2014 8:43 AM
    Sunday, September 28, 2014 3:16 PM
  • Hi ,

    Here are few questions? 

    Where is your CRM server? Is it in the same country where you are residing?

    As your CRM server is some where else it will take local time of the server.

    So you need to convert it into your local time. 

    var currentUserSettings = xrm.RetrieveMultiple( new QueryExpression("usersettings") { ColumnSet = new ColumnSet("timezonecode"), Criteria = new FilterExpression { Conditions = { new ConditionExpression("systemuserid", ConditionOperator.EqualUserId) } } } ).Entities[0].ToEntity<UserSettings>(); int timeZoneCode = currentUserSettings.TimeZoneCode.GetValueOrDefault(); LocalTimeFromUtcTimeRequest reqTimeConversion = new LocalTimeFromUtcTimeRequest { UtcTime = DateTime.UtcNow, TimeZoneCode = timeZoneCode }; LocalTimeFromUtcTimeResponse respTimeConversion = (LocalTimeFromUtcTimeResponse)xrm.Execute(reqTimeConversion); DateTime localTime = respTimeConversion.LocalTime;

    Thanks,


    Sreeni Pavalla

    Monday, September 29, 2014 6:07 AM