views:

41

answers:

5

the following code below

var unixDate = new Date('07/28/2010');
    var unixMonth = unixDate.getMonth();
    var unixDay = unixDate.getDate();
    var unixYear = unixDate.getFullYear();
    alert(filterDate.value);
    alert(unixMonth);
    alert(unixDay);
    alert(unixYear);

should give me month 07 but it alrets 06....whys that

+3  A: 

The months are 0-based, 0=January

http://www.w3schools.com/jsref/jsref_getMonth.asp

Roman Zenka
+5  A: 

Months are zero based. Just do +1. See also Date.getMonth() at MDC:

The value returned by getMonth is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.

BalusC
+2  A: 

My guess would be that 0 = January and thus your enumeration is slightly off.

JB King
+2  A: 

.getMonth returns a zero indexed month. So, 0 = January, and 11 = December.

Vincent McNabb
+2  A: 

Use:

var unixMonth = unixDate.getMonth() + 1;

.getMonth returns a zero indexed month.

0  = January
11 = December

More Info

The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.

Note: January is 0, February is 1, and so on.

Sarfraz