Javascript new Date() not working…sometimes

I can’t figure this out for the life of me. The below code does not give me the day of the week, but instead give me the ‘Choose date’ option:

var year = '21';
var month = '4';
var date = '3';

var dow = new Date(parseInt(year), parseInt(month) - 1, parseInt(date)).getDay() || 'Choose date';


If I change the month to ‘3’, it works fine. In fact, it works for the vast majority of combinations I have tried. Another combination that doesn’t work is year = ’21’, month = ’10’, date = ‘2’. What am I missing? I’m trying this in Chrome. Please, help!

52 thoughts on “Javascript new Date() not working…sometimes”

Leave a Comment