CRM DateTime and Displaying in Different Time Zone RRS feed

  • Question

  • I am not sure how to handle the following scenario from a portal.

    I have an entity called Event with a Start and End Date and option set field which displays 4 different time zone which the user can pick from. In CRM a user time zone setting might be different from the time zone where the Event will be occurring.

    I need to display to the correct Start Date, End Date and Time Zone on a portal based on what was entered on the Event entity. I know CRM stores the dates in UTC offsetting the CRM user time zone.

    What do I need to do to get the Dates to show up correctly on the portal without time been offset based on the CRM user time zone setting.

    Please Help!!.

    Thursday, June 27, 2013 11:30 PM

All replies

  • Hi,

    As you rightly say, the datetimes will always be converted into UTC in the database based on the user's timezone setting. 

    If you retrieve the date using the SOAP SDK webservices - you'll get it in UTC format, and then you need to convert it to the correct time zone using a suitable function (such as the TimeZone info class)

    I did a blog post about date/times in CRM which might help - http://www.develop1.net/public/post/Dynamics-CRM-DateTimes-the-last-word.aspx


    Scott Durow
    Blog www.develop1.net    Follow Me
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, June 28, 2013 7:46 AM
  • We implemented similar functionality by having three fields:

    1. a text field for the date & time entry (JS library allowed for quick entries like "6/28 3p")
    2. a lookup to a custom timezone entity (based on TZDB)
    3. a hidden CRM date/time field to store the UTC time

    A plugin fired on update that used the .Net timezone classes to calculate UTC and store it in the Date/Time field.

    Friday, June 28, 2013 12:40 PM
  • I am still not sure how to handle it at the moment what do I need to do?

    Currently I have the following and the user entering the event has the user Time Zone setting set to Central Time and the portal web server is hosted on the Eastern time. On the Portal I want the dates  to be displayed  as 06/30/2013 9.00 AM and not 06/30/2013 10.00 AM. Users entering the events will be on different time zones.

    • Edited by SPCRM2011 Friday, June 28, 2013 2:41 PM changes
    Friday, June 28, 2013 2:40 PM
  • Since Start Date in your form is a CRM DateTime it will go through a "conversion process" (what Scott describes in his blog) to store it to UTC based on the user's timezone setting.  If one user is in CST and they enter 9:00AM it will convert to (currently -5 UTC w/ daylight savings)  2:00PM UTC.  If a PST user enters 9:00AM it will be 4:00PM UTC).  That's why we chose to have the users enter the date/time as a string and we handled the UTC conversion in .Net. 

    Generally we display the string version of the date/time and tack on the timezone abbreviation.  The CRM date/time is used by the activity entity for scheduling to avoid double-booking international talent, but does not display to our portal users.

    Friday, June 28, 2013 5:25 PM
  •  So are you saying you are letting your user enter the time in CRM in free text? And how do you take into consideration of portal web server local time? Because SDK returns time in UTC and when you convert to local time its going to be displayed in the web server local time.

    I am still all confused. I can you please outline all the steps I need to take?

    • Edited by SPCRM2011 Friday, June 28, 2013 9:48 PM change
    Friday, June 28, 2013 9:46 PM
  • Step 1:

    CRM user enters "6/27/13 7:00 PM" into free text field - Event Date and selects America/New York (EST) in Event Timezone field

    Step 2:

    Create/Update plugin fires and calculates the UTC time (6/27/13 11:00PM) and saves in date/time field - UTC Event Date

    Step 3:

    Portal user displays page or SSRS report that outputs Event Date + Event Timezone as a string on the report.

    Friday, June 28, 2013 10:33 PM
  • I don't think Scott's blog post adequately describes the conversion process...   I need to look up the timezone of a specific user, not hard-code the time zone code like Scott did:

        TimeZoneCode = 85 // Timezone of user

    I need something like this instead

           TimezoneCode = GetTimeZoneCodeForUser(userId)

    Why would anyone want to hard-code the TImezoneCode?  Only seems useful if you know all your users are in the same time zone.

    • Edited by Paul Abrams Thursday, December 22, 2016 8:19 PM because
    Thursday, December 22, 2016 8:17 PM