CRM 2011 – Comparing only dates in Javascript

I was trying to compare some dates in Javascript today, I wanted to know if one dates was less than another, if it was I set the a status to overview.

When I compared the dates I found my CRM date had set the hours, minutes, seconds to 0,0,0 which is correctly because I wasn’t interested in storing the hours and minutes.

When I compared that date to todays date in Javascript it was coming up less because todays date had the current time in it.

so to compare the dates I used the setHours method to blank the time from the date then you can compare just the date values.


var reviewDate = Xrm.Page.getAttribute(“followupby”).getValue();
var currentTime = new Date();
currentTime.setHours(0, 0, 0, 0);
if (reviewDate < currentTime) {
//kpi incomplete
} else {


One thought on “CRM 2011 – Comparing only dates in Javascript

  1. Garima June 13, 2014 / 2:58 pm

    thanks for posting this.. helpful..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s