Check Date Range is Valid in Javascript

by Sasikumar 2014-06-07 15:04:51

To check whether the date range is valid or not in javascript use the following function
Javascript Function:
function checkDateRange(startDate,endDate,deliminator)
{
    return new Date(startDate.split(deliminator).reverse().join(deliminator)) <= new Date(endDate.split(deliminator).reverse().join(deliminator));
}
Example:
alert(checkDateRange('10-07-2012','11-07-2012','-'));
alert(checkDateRange('10-07-2012','09-07-2012','-'));
Function would return "true" or "false" based on the data passed.

Note: Pass date in "MM-DD-YYYY" format.
61
like
0
dislike
0
mail
flag

You must LOGIN to add comments
Guna

Another way to do this is, use strtotime and compare timestamps.