Date Time in MS CRM

Date-time conversion to local ….

Using the SOAP endpoint, you will always get a UTC date, to get into a local date on a client (assuming that the client has their datetime set correctly) use DateTime.ToLocalTime, but if you can’t guarentee the time zone settings then use ..

the LocalTimeFromUtcTimeRequest.

LocalTimeFromUtcTimeRequest convert = new LocalTimeFromUtcTimeRequest
 UtcTime = Convert.ToDateTime(opportunity.Attributes["hsb_issuedate"]), 
 TimeZoneCode = Convert.ToInt32(DateTimeKind.Local) // Timezone of user
 LocalTimeFromUtcTimeResponse response = (LocalTimeFromUtcTimeResponse)service.Execute(convert);

String localDate = response.LocalTime.ToString("yyyy-MM-dd");


So in summary, here are the key points to remember:

  1. Date/Times are always stored in the MSCRM database as UTC dates.
  2. When querying the Base table or views for an entity (e.g. ContactBase or Contact), the dates will be UTC.
    E.g. the following dates will be in UTC
    Select birthdate From ContactBase
    Select birthdate form Contact
  3. When query the Filtered Views, dates will be in the local time specified in the current user’s settings. There is another field provided that is suffixed by UTC that provides the raw date without any convertion.
    E.g. The first date will be local time zone correct, and the second field will always be utc
    Select birthdate,birthdateutc from FilteredContact
  4. When sending a date/time in SOAP SDK Message (e.g. create/update), the date will default to local time if you use a DateTime.Parse – and if you want to send a UTC time, you must set the DateTimeKind to UTC.
  5. Important: When querying the SOAP SDK, any date/times will be returned as UTC dates, and must be converted to local time using DateTime.ToLocalTime if you know that the locale of the current process is set correctly, or the LocalTimeFromUtcTimeRequest SDK message.
  6. When importing &updating data via the Import Wizard, date/times must be specified in the local date of the user who is importing them.


You can explore more here..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s