2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

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?
userimage

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();
        from_date.setFullYear(fromdate[2],fromdate[1]-1,fromdate[0]);
        var todate = to_date.split('-');
        to_date = new Date();
        to_date.setFullYear(todate[2],todate[1]-1,todate[0]);
        if (from_date > to_date )
        {
            alert("Invalid Date Range!nStart Date cannot be after End Date!")

            return false;
        }


Answer is