[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

javascript get month gives wrong month

Posted on 2002-06-07
6
Medium Priority
?
821 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one 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…
Suggested Courses

834 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