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 {

2 thoughts on “CRM 2011 – Comparing only dates in Javascript

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

    thanks for posting this.. helpful..


  2. Sree Bindu July 28, 2017 / 10:51 am

    Great post. But if review date and current date are equal, though we set each of them to setHours(0,0,0) and compare them, the result of checking the equality is false. I need this to work in my scenario. But it wont.


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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.