Skip to content

Instantly share code, notes, and snippets.

@DynCon365
Created April 4, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DynCon365/64c47edef24d9c4207d8a305a0b7efce to your computer and use it in GitHub Desktop.
Save DynCon365/64c47edef24d9c4207d8a305a0b7efce to your computer and use it in GitHub Desktop.
Dynamics 365/CRM | Get the value of a Date field (01/31/2018 or 31/01/2018)
// Get the value of the Opportunity Est. Close Date
var date = Xrm.Page.data.entity.attributes.get("estimatedclosedate").getValue();
if (date != null) {
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
month++;
// Add leading 0's to single digit days and months
if (day < 10) {day = "0" + day;}
if (month < 10) {month = "0" + month;}
// Create a variable with the formatted date as MM/DD/YYYY
var formattedDate = month + "/" + day + "/" + year;
// Create a variable with the formatted date as DD/MM/YYYY
//var formattedDate = date + "/" + month + "/" + year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment