By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

date compare

P: 27
i have to compare currentdate with a date in javascript

my completiondate variable is having value 29/12/2007 00:00:00

var today_date= new Date()
var date2 = new Date(completiondate);
alert(date2)

here alert displayes a wrong date for me (Tue May 12 00:00:00 UTC+0100 2009)
why ?

how to compare 'today' and 'date2'

thanks
mp
Jan 3 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
The completion date is in the wrong format or at least the month and date are in the wrong order. 29/12/2007 is the 29th month and 12th date. JavaScript automatically moves the date forward if a number is too big, so since there are only 12 months, it moves forward 2 years (29 = 12 + 12 + 5), so you end up with a date of May 12, 2009.

To set the date, use the set*** methods - see this date reference.
Jan 3 '08 #2

P: 27
mpl
can u advice how to use the Setdate function here in my example ?


thanks
mp


The completion date is in the wrong format or at least the month and date are in the wrong order. 29/12/2007 is the 29th month and 12th date. JavaScript automatically moves the date forward if a number is too big, so since there are only 12 months, it moves forward 2 years (29 = 12 + 12 + 5), so you end up with a date of May 12, 2009.

To set the date, use the set*** methods - see this date reference.
Jan 4 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Use setFullYear() to set the full date. See an example.
Jan 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.