Jul 12, 2012

CrmDateTime to/from DateTime

This is a simple kind of conversion, but for some reason, I had to play around to figure it out. So I am writing it here.

When converting to/from CrmDateTime in C# key is the “Value” attribute. We can simply read it and also assign it.

CrmDateTime to DateTime

DateTime _datetime = Convert.ToDateTime(dateTime.Value)

DateTime to CrmDateTime

 CrmDateTime _crmDataTime = new CrmDateTime();
 _crmDataTime.Value = _datetime.ToString("s");

Also, we can modify date time related other attributes this way.

No comments:

Post a Comment