For the latest updates to this post please visit the original posting here: Good to Know JavaScript / CRM Date Time Difference
Here at PowerObjects, we use JavaScript frequently. It’s a powerful tool for Microsoft Dynamics CRM customizations. Now and then, we observe a funny quirk about how JavaScript and CRM work together. Take the JavaScript Date () function and how it relates to CRM date time, for instance.
JavaScript Date() function will take year, month, day, hours, minute and seconds as the parameters and convert it into Date object in dd/mm format for CRM. While in JavaScript Date(), the month starts in 0 for January. So, if we are feeding JavaScript Date() with 2012, 11, and 26 as the year, month and day parameters, it writes into CRM as 26 December 2012!
In the following screenshot, we can see our code and how the variable’s month has the value 11. The new Date variable convertedDate via Date() has a result of 26 December 2012 instead of 26 November 2012.
Once we know that the month start value is different between JavaScript Date() and CRM, we can now convert Date correctly.
So repeat after me: JavaScript Date month start in 0 for January, CRM starts in 1 for January. The more you know!
If you found this post useful, here are some more posts about using JavaScript in CRM:
- Turning on CRM-style JavaScript for the Polaris/UR12 Update
- Use Javascript to Update Price Per Unit When Selecting a Product in Dynamics CRM 2011
- Tooltips for Disabled Ribbon Buttons
- Using JavaScript to Set the Value in a Read-Only Field
Happy CRM’ing!
The post Good to Know JavaScript / CRM Date Time Difference appeared first on PowerObjects.