views:

89

answers:

2

Hi all, I can't seem to figure out what is wrong with my code. Maybe it would be simpler to just compare date and not time. Not sure how to do this either and I searched but couldn't find my exact problem.

BTW, when I display the two dates in an alert, they show as exactly the same.

My code:

window.addEvent('domready', function() {
var now = new Date();
var input = $('datum').getValue();
var dateArray = input.split('/');
var userMonth = parseInt(dateArray[1])-1;
var userDate = new Date();
userDate.setFullYear(dateArray[2], userMonth, dateArray[0], now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());

if(userDate > now)
{
    alert(now+'\n'+userDate);
}
});

Perhaps there is a simpler way to compare dates and not including the time. Hope someone has an answer...

Thanks!

A: 

The date.js library is handy for these things. It makes all JS date-related scriping a lot easier.

Diodeus
A: 

Make sure you construct userDate with a 4 digit year as setFullYear(10, ...) !== setFullYear(2010, ...).

Alex K.
it is using 4 digit year.
moleculezz