Comparing Two dates

Scenario:

We have a start date and a Due date and need to a validation where Due date date should be a date after the Start date.

Solution:

Usually we can use the JavaScript Date() function. But you can’t compare two dates using that. Better approach to make comparison between dates is to use getTime() function. This function lets converting date into numeric value to directly compare them.

//clientScrip example code.
//Note: this code is just an example. Not a completed Script

var startDate =  curentRec.getText({
    fieldId:'start_date'
});
var endDate =  curentRec.getText({
    fieldId:'end_date'
});

var sDate = new Date(startDate).getTime();
var dDate = new Date(endDate).getTime();

if(sDate>dDate){
    alert("Due date should be greater than start date")
    return false;
}

Leave a comment

Your email address will not be published. Required fields are marked *