Solved

javascript get month gives wrong month

Posted on 2002-06-07
6
815 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
age from date of birth 4 51
Getting Random number with min and max value. 2 32
HTML Anchor Link Problem 3 35
Help with Javascript to round decimal points to 2 13 9
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-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

839 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