Leon van der Veen Leon van der Veen - 3 months ago 9
Javascript Question

compare string with todays date in javascript

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

Any suggestions?

Answer
    <script type="text/javascript">

var q = new Date();
var m = q.getMonth()+1;
var d = q.getDay();
var y = q.getYear();

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>
Comments