Solved

javascript get month gives wrong month

Posted on 2002-06-07
6
816 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:johnh619
ID: 7063705
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
ID: 7063863
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
ID: 7063943
>> 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 7069184
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
ID: 8276040
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
ID: 8360631
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

726 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