locked
Date and time field has different values at server and client? RRS feed

  • General discussion

  • I have a a strange problem with the behaviour of a date field in CRM. On a custom entity I have a from date field. I am only interested in the date part of this. So if someone enters 24/8/2013 my background code will start processing a set of actions from Saturday 24/8.

    At the client the value of this field is 00:00 24/8/2013 but by the time it is picked up in the background code on the server the value has become 23:00 23/8/2013 and the system processes all actions from the previous Friday. My initial thought was that microsft were doing something stupid with time zones but all the systems on my network are set to use GMT with no daylight savings time and they all synchronise to a single parent clock.

    So why can microsoft CRM not tell the time?

    Tuesday, August 6, 2013 5:11 PM

All replies

  • Hi,
    CRM 2011 stores datetime in UTC format. This means that you are currently in a UTC+1 timezone (for example now is 18.00 UTC, in UK will be 19.00 because is BST timezone)

    You said background code, I imagine is C#, in this case you need to get the LocalTime from the datetime field to get the right value (based on the user used for the conncection) 

    for example:

    DateTime createdOn = ((DateTime)account["createdon"]).ToLocalTime();


    My blog: www.crmanswers.net


    Tuesday, August 6, 2013 6:09 PM
  • Hi,
    CRM 2011 stores datetime in UTC format. This means that you are currently in a UTC+1 timezone (for example now is 18.00 UTC, in UK will be 19.00 because is BST timezone)

    You said background code, I imagine is C#, in this case you need to get the LocalTime from the datetime field to get the right value (based on the user used for the conncection) 

    for example:

    DateTime createdOn = ((DateTime)account["createdon"]).ToLocalTime();


    My blog: www.crmanswers.net


    "all the systems on my network are set to use GMT with no daylight savings time and they all synchronise to a single parent clock."

    I'll try it as a solution but if it is so then it's yet another part of CRM that's broken because every system in my network is set to GMT with no daylight savings so if CRM thinks there's a difference between local time in GMT and UTC then it's just lying to me again.

    (I am growing to despise CRM, it really is a bloated cumbersome prototype that is just fit for the bin and nothing else)



    • Edited by J N Brand Tuesday, August 6, 2013 9:42 PM
    Tuesday, August 6, 2013 9:40 PM
  • There are definitely issues with 'date-only' attributes in CRM, it's been listed on the Connect site as something we would like to have fixed for what seems like forever. With that said, the CRM UI timezone information is not driven by the machine settings but rather by the settings selected in the options in CRM - which I assume you have set to GMT, but CRM /probably/ has baked-in allowances for BST, which would put you an hour ahead during the summer, and thus give you the offset presently, regardless of if the machines themselves are set to ignore BST. Sadly the most effective workarounds to get a true 'date-only' field seem to be either 1) defaulting 'date-only' values to use something between 10:59 - 12:00 instead of 00:00 which will result in the same date when converted in /almost/ all timezones (but never 100%). or 2) just using a text field to store the date. Here's one (of many) articles about the issue. http://blog.customereffective.com/blog/2009/07/date-only-fields-display-different-dates-depending-on-users-time-zone.html

    Wednesday, August 7, 2013 5:27 AM
  • As Ken Heiman explained correctly, it is necessary to consider the selected timezone inside CRM.

    You can check by File -> Options -> General Tab -> Set the time zone you are in 


    My blog: www.crmanswers.net


    Wednesday, August 7, 2013 8:16 AM
  • Thanks Ken and Guido,

    Yes that is the solution even though everything is set to GMT, CRM still applies daylight savings. In the CRM settings GMT is selected but CRM has multiple GMT settings including "GMT (Greenwich Mean Time)" and "GMT (UTC)". There is no option to choose whether or not to apply daylight savings. Tell it to  use UTC and it works, select GMT and it fails.

    This is wrong for several reasons. First of all it is a lie, if I select GMT and CRM chooses to use BST then it has lied to me. Secondly, GMT and UTC are the same thing (apart from subsecond differences due to the Earth's rotation varying), so having two settings for the same thing tells me that CRM doesn't understand time. Third there is no way to select a timezone other than GMT and not have daylight savings imposed on you (fortunately in my case my local time is GMT without daylight savings). Hardcoding the time part of a date field to noon would be a workround for most cases but will still get the date wrong on occasions.


    • Edited by J N Brand Thursday, August 8, 2013 9:12 PM
    Thursday, August 8, 2013 11:46 AM