javascriptdatedate-comparison

compare string with today's date in JavaScript


I've got a string from an input field which I use for date with a format like this 25-02-2013. Now I want to compare the string with today's date. I want to know if the string is older or newer then today's date.

Any suggestions?


Solution

  •     <script type="text/javascript">
    
    var q = new Date();
    var m = q.getMonth()+1;
    var d = q.getDay();
    var y = q.getFullYear();
    
    var date = new Date(y,m,d);
    
    mydate=new Date('2011-04-11');
    console.log(date);
    console.log(mydate)
    
    if(date>mydate)
    {
        alert("greater");
    }
    else
    {
        alert("smaller")
    }
    
    
    </script>