We help IT Professionals succeed at work.

Javascript comparing dates

JimmyDeuce
JimmyDeuce asked
on
Medium Priority
168 Views
Last Modified: 2012-05-12
I have a calendar that I am making and I can't allow the user to go out past two years. when they clcik the"nextMonth" button I need to do the following.

date1 = today
date2 = today + 2 years

So when they get to the November 2013 thank can't proceed to December 2013.

I am having a tough time and I think that it's because the time on the dates are throwing things off. I need to compare just the month and year.

Any thoughts?

tx

Jim
Comment
Watch Question

Web Programmer/Technician
Commented:
var date1 = new Date();	// today
var date2 = new Date();	// also today
date2.setFullYear(date2.getFullYear()+2);	// now today + 2 years

Open in new window


Commented:
var date1= Date(); //today (relative to browser not server)
var date2= Date();
date2.setFullYear(2+date2.getFullYear()); //adjust + 2 years
//comparing date objects is simple
//date1>date2 returns false

 

Author

Commented:
Thanks you

Explore More ContentExplore courses, solutions, and other research materials related to this topic.