2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Compare two dates with JavaScript

I have two values(dates) coming from text boxes. Is there any way to compare those values of two dates greater than, less than, and not in the past using JavaScript?

I am not getting any format what you want to compare.Any way here is some piece of code from my analysis hope it will helpful for you.

        from_date ='10-09-2015';
        to_date = '05-05-2015';
        var fromdate = from_date.split('-');
        from_date = new Date();
        var todate = to_date.split('-');
        to_date = new Date();
        if (from_date > to_date )
            alert("Invalid Date Range!nStart Date cannot be after End Date!")

            return false;

Answer is