Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Include the code below and you can just do:</p> <pre><code>datetime.toCRMFormat(); </code></pre> <p>This code was found in this <a href="http://www.bizforward.cws-international.com/2011/03/09/useful-javascript-functions-and-methods-for-crm-2011-cws-crm-utils-js-library/" rel="nofollow">useful CRM 2011 JS library</a> </p> <pre><code>// Formats the date to CRM format Date.prototype.toCRMFormat = function() { var d = this; var f = d.Format("yyyy-mm-ddThh:MM:ss+" + (-d.getTimezoneOffset()/60) + ":00"); return f; } // Formats the date into a certain format Date.prototype.Format = function(format) { var d = this; var f = ""; try { f = f + format.replace( /dd|mm|yyyy|MM|hh|ss|ms|APM|\s|\/|\-|,|\./ig , function match() { switch(arguments[0]) { case "dd": var dd = d.getDate(); return (dd &lt; 10)? "0" + dd : dd; case "mm": var mm = d.getMonth() + 1; return (mm &lt; 10)? "0" + mm : mm; case "yyyy": return d.getFullYear(); case "hh": var hh = d.getHours(); return (hh &lt; 10)? "0" + hh : hh; case "MM": var MM = d.getMinutes(); return (MM &lt; 10)? "0" + MM : MM; case "ss": var ss = d.getSeconds(); return (ss &lt; 10)? "0" + ss : ss; case "ms": return d.getMilliseconds(); case "APM": var apm = d.getHours(); return (apm &lt; 12)? "AM" : "PM"; default: return arguments[0]; } }); } catch(err) { } return f; } </code></pre> <p>Or if you want them as regular functions instead of extensions on Date such as <code>dateToCRMFormat(datetime)</code></p> <pre><code>// Formats the date to CRM format function dateToCRMFormat (date) { return dateFormat(date, "yyyy-mm-ddThh:MM:ss+" + (-date.getTimezoneOffset()/60) + ":00"); } // Formats the date into a certain format function dateFormat (date, format) { var f = ""; try { f = f + format.replace( /dd|mm|yyyy|MM|hh|ss|ms|APM|\s|\/|\-|,|\./ig , function match() { switch(arguments[0]) { case "dd": var dd = date.getDate(); return (dd &lt; 10)? "0" + dd : dd; case "mm": var mm = date.getMonth() + 1; return (mm &lt; 10)? "0" + mm : mm; case "yyyy": return date.getFullYear(); case "hh": var hh = date.getHours(); return (hh &lt; 10)? "0" + hh : hh; case "MM": var MM = date.getMinutes(); return (MM &lt; 10)? "0" + MM : MM; case "ss": var ss = date.getSeconds(); return (ss &lt; 10)? "0" + ss : ss; case "ms": return date.getMilliseconds(); case "APM": var apm = date.getHours(); return (apm &lt; 12)? "AM" : "PM"; default: return arguments[0]; } }); } catch(err) { } return f; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload