withdraw how many days left until March 8. what am I doing wrong?

var a=new Date(), b=new Date(), c=new Date(), d, e, f, s1, s2; b.setDate(7); b.setMonth(3); b.getYear(); d=Date.parse(a); e=Date.parse(b); if (d<e) {b.setFullYear(b.getFullYear+1)} e=Date.parse(b); s1=Math.floor((de)/1000/60/60/24); alert("do 8 marta dney"+s1); 

    1 answer 1

    You incorrectly specify the number of the month, in javascript they begin with 0 (0 - January, 2 - March). If you take a known date, the code can be slightly simplified:

     var currentDate = new Date(), needDate = new Date(2014, 2, 8), remainingDays = Math.ceil( ( needDate - currentDate ) / 1000 / 60 / 60 / 24 ); alert( remainingDays );