+ Start a Discussion
Vrushali Pradhan 10Vrushali Pradhan 10 

compare dates in javascript on a custom button

I am trying to compare dates  to allow the clone functionality to work. I have following javascript on a custom button but it doesnt work.
var SCAssgn = "{!Quote__c.CreatedDate}"; 
var mydate = new Date(SCAssgn); 
var cutoff = new Date("10/6/2017") 
alert(cutoff) ; 
if(SCAssgn < cutoff ) 

alert("You cannot clone this quote. Please create a new Quote"); 

else { 
Malni Chandrasekaran 2Malni Chandrasekaran 2

Please try,
if (SCAssgn.getTime() > cutoff.getTime())

We cannot compare the date object directly.
hope this helps!
Deepak Pandey 13Deepak Pandey 13
URL - https://salesforce.stackexchange.com/questions/497/how-to-compare-2-dates-in-javascript-on-a-visualforce-page
I think it will help.