setDate(31) for AUG not working - shows Aug 1st

Hi All,
I need to compare a date of Aug 31st, and a year against today's date
and the below does give me Aug 31st, it gives me Aug 1st,

   var dteLimit = new Date();
  alert('Initial Setting');

   dteLimit.setDate(30);  ----gives Aug 30
   dteLimit.setDate(14);  ----gives Aug 14
   dteLimit.setDate(31);  ----Does NOT give Aug 31
BILL CarlisleAPEX DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

James RodgersConnect With a Mentor Web Applications DeveloperCommented:
cahnge teh sequence

it doesnt understand how toi handle 31 when it does already know the month
contactkarthiConnect With a Mentor Commented:
it tries to set 31 for nov which will be dec 1

after that you set month as aug so you see aug 1

set the month first and then the date
BILL CarlisleAPEX DeveloperAuthor Commented:
Ha! that makes sense!
Duh.. Thank you so much!
b0lsc0ttIT ManagerCommented:
Good answer guys!  Just to add a little follow up the same principle is true if you are setting the year.  Make sure you do that first before any changes to month or day.  It won't always matter but can make a big difference at times, especially in February. :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.