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();
   dteLimit.setDate(31);
   dteLimit.setMonth(7);
  alert('Initial Setting');
  alert(dteLimit.toLocaleString());

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

Improve company productivity with a Business Account.Sign Up

x
 
James RodgersConnect With a Mentor Web Applications DeveloperCommented:
cahnge teh sequence
dteLimit.setMonth(7);
dteLimit.setDate(31);

it doesnt understand how toi handle 31 when it does already know the month
   
0
 
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
0
 
BILL CarlisleAPEX DeveloperAuthor Commented:
OOOOOOHHHHHHH!!!!
Ha! that makes sense!
Duh.. Thank you so much!
0
 
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. :)

bol
0
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.