Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date.getDay() javascript returns wrong day

Hi I'm new in javascript I have such javascript code

alert(DATE.value); var d = new Date(DATE.value); var year = d.getFullYear(); var month = d.getMonth(); var day = d.getDay(); alert(month); alert(day); if(2012 < year < 1971 | 1 > month+1 > 12 | 0 >day > 31){     alert(errorDate);     DATE.focus();     return false; } 

take for instance: DATE.value = "11/11/1991"

when I call alert(day); it shows me 3;
when I call alert(d); it is returns me correct info.

like image 917
Aleksei Bulgak Avatar asked Nov 13 '12 10:11

Aleksei Bulgak


1 Answers

use .getDate instead of .getDay.

The value returned by getDay is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.

like image 97
Luca Rainone Avatar answered Sep 28 '22 02:09

Luca Rainone