CRM 2015 Update 1: Store date and time values with or without time zone information

Until the previous release of CRM, all date and time values in CRM were time zone aware, including those with the Date Only format.

Use the new DateTimeAttributeMetadata.DateTimeBehavior property to store date and time values with or without time zone information. Until now, all the date and time values in CRM were stored using the user’s local time zone information, including those with the DateOnly format. The CRM system use to convert values from the user’s local time zone to Coordinated Universal Time (UTC) on update, and back to the current user’s time zone when displayed on the form.

This was not an optimal experience for storing and using:

  • Date only values without the time information, such as birthdays and anniversaries.
  • Date and time values without the time zone information so that users across multiple time zones see the same date and time value, such as the hotel check-in time.

You can use the DateTimeBehavior enumeration to specify a value for the DateTimeBehavior property, or can directly specify the string value. The DateTimeBehavior property can have any of the following three values:

The following sample code demonstrates how to set a DateOnly behavior for a new attribute:

// Create a date time attribute

DateTimeAttributeMetadata dtAttribute = new DateTimeAttributeMetadata


// Set base properties

SchemaName = “new_Birthday”,

DisplayName = new Label(“Birthday”, _1033),

Description = new Label(“Birthday”, 1033),

DateTimeBehavior = DateTimeBehavior.DateOnly

Format = DateTimeFormat.DateOnly,

ImeMode = ImeMode.Disabled



In the above code, you can also set the value of the DateTimeBehavior property by directly specifying the string value: DateTimeBehavior = “DateOnly”

Use the DateTimeAttributeMetadata.Format property to specify the date/time display format of the attribute irrespective of how it is stored in the database. You can use the DateTimeFormat enumeration to specify the display format: DateAndTime or DateOnly.

If the DateTimeBehavior property is set to DateOnly, you cannot set or change the value of the Format property to DateAndTime.



***Important: This topic is pre-release documentation and is subject to change in future releases.

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