Setting Datetime field in MS CRM- Quick Tip

If you want to set a datatime field in MS CRM 2011/2013/2015, you can follow below code for the same

//Set current Datetime field in Javascript

var today=new Date();
Xrm.Page.getAttribute('fieldname').setValue(today);

//Set Current datetime in Server side code
DateTime currentDate=DateTime.Now;
_EntityObject[“AttributeName”]=currentDate;

//Set retrieved date using Rest
var  dateVal = dateReviver(Resultset.DateAttribute); 
//refer http://msdn.microsoft.com/en-us/library/gg328025.aspx for dateReviver function

Xrm.Page.getAttribute('targeAttributeName').setValue(dateVal);

Enjoy!!!

Leave a Reply

Your email address will not be published. Required fields are marked *