Archive

Posts Tagged ‘Date and Time’

CRM Date and Time field – Behaviors

December 18, 2016 2 comments

Recently, I was asked a question in my blog on what is the significance of the different ‘Behaviors’ of ‘Date and Time’ field.

There are 3 different behaviors available for ‘Date and Time’ field.

Date and Time field behavior

Date and Time field behavior

User Local:

  • Time zone would be applied on this behavior. Field’s Date and time would be shown based on current user’s time zone.
  • ‘User Local’ behavior of a Field can be changed to other behaviors after field creation.
  • If the field behavior changed,
    • Behavior change takes affect only to the newly added/updated field values.
    • The existing field values remain in the database in the UTC time zone format.
  • To change the behavior of the existing field values from UTC to Date Only we would need SDK call (ConvertDateAndTimeBehaviorRequest)
  • Below is the sample code

var request = new ConvertDateAndTimeBehaviorRequest(){
Attributes = new EntityAttributeCollection() {
new KeyValuePair<string, StringCollection>(“account”, new StringCollection()
{ “new_sampledatetimeattribute” })
},
ConversionRule = DateTimeBehaviorConversionRule.SpecificTimeZone.Value,
TimeZoneCode = 190, // Time zone code for India Standard Time (IST) in CRM
AutoConvert = false // Conversion must be done using ConversionRule
};

// Execute the request
var response = (ConvertDateAndTimeBehaviorResponse)_serviceProxy.Execute(request);

 

    • Conversion rules:
      • SpecificTimeZone: Converts UTC value to a DateOnly value as per the specified time zone code.
      • CreatedByTimeZone: Converts UTC value to a DateOnly value that the user who created the record.
      • OwnerTimeZone: Converts UTC value to a DateOnly value that the user who owns the record.
      • LastUpdatedByTimeZone: Converts UTC value to a DateOnly value that the user who last updated the record
  • When you execute the ConvertDateAndTimeBehaviorRequest message, a system job (asynchronous operation) is created to run the conversion request.

Date Only:

  • Time zone isn’t applicable to this behavior. Field values are displayed without the time zone conversion.
  • The time portion of the value is always 12:00AM
  • This Behavior can’t be changed to other behavior types, once it’s set.
  • The Date Only behavior is good for cases when information about the time of the day and the time zone isn’t required, such as such as birthdays or anniversaries.

Time-Zone Independent:

  • Time zone isn’t applicable to this behavior. The field values are displayed without the time zone conversion.
  • This Behavior can’t be changed to other behavior types, once it’s set.
  • You can use this behavior when time zone information isn’t required, such as the hotel check-in time.

Refer MSDN article for more details.

🙂

Categories: CRM Tags: , ,