Solved

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

Posted on 2007-11-15
4
324 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:bcarlis
4 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 50 total points
Comment Utility
cahnge teh sequence
dteLimit.setMonth(7);
dteLimit.setDate(31);

it doesnt understand how toi handle 31 when it does already know the month
   
0
 
LVL 17

Assisted Solution

by:contactkarthi
contactkarthi earned 50 total points
Comment Utility
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
 
LVL 2

Author Comment

by:bcarlis
Comment Utility
OOOOOOHHHHHHH!!!!
Ha! that makes sense!
Duh.. Thank you so much!
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now