[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

javascript get month gives wrong month

Posted on 2002-06-07
6
Medium Priority
?
820 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 200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

650 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