Solved

javascript get month gives wrong month

Posted on 2002-06-07
6
811 Views
Last Modified: 2012-05-04
If I tell it to get month and then put in if
statement such that if the month is this month
then document write so and so, but it does not write
and if I put in if month is one month earlier than present
then it works okay, so it is off by one month but the day is correct. I look at my calendar and it says todays date which is june 7 but the computer thinks it is may 7. How could this be?
0
Comment
Question by:johnh619
6 Comments
 

Author Comment

by:johnh619
Comment Utility
When I said I look at the calendar I mean the calendar in the computer not the one on my wall.
0
 
LVL 7

Accepted Solution

by:
axis_img earned 50 total points
Comment Utility
Hello...

The getMonth() method returns an integer between 0 and 11, which corresponds as follows:

0 - Jan
1 - Feb
...
...
10 - Nov
11 - Dec

For more information regarding dates in javascript, please see here:
http://developer.netscape.com/docs/manuals/js/client/jsref/date.htm

For information specifically regarding getMonth(), see here:
http://developer.netscape.com/docs/manuals/js/client/jsref/date.htm#1193744

If you have any other questions, please let me know...
Barry
0
 
LVL 12

Expert Comment

by:lexxwern
Comment Utility
>> When I said I look at the calendar I mean the calendar in the computer not the one on my wall.

lol!/

but ya you must  have made a common mistake, 0 is the first month and so on... ( as  axis_img suggested)
0
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.

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Also be sure your getYear() returns 4 digits like this:

function y2k(yy) {
   if (isNaN(yy) return 0;
   if (yy < 1900) yy+=1900;
   return yy;
}


today = new Date();
yyyy = y2k(today.getYear())

or if you target v4 browsers and higher only, always use getFullYear()
0
 
LVL 12

Expert Comment

by:ahosang
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to axis_img
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Expert Comment

by:modulo
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now