nowdate = new Date(); wardate = new Date(); var d = (nowdate.getFullYear() - wardate.setFullYear(1945)) / 1000 / 24 / 12; document.write(d); 

I need a script that calculates how many years have passed since 1945. The variable d takes a value in milliseconds, how to translate it into years?

  • one
    31600800000 by 31600800000 , obviously. - etki
  • This is the answer 24.523937354813803 - hik
  • one
    In general, it was sarcastic, but, nevertheless, almost correct comment: (new Date('2015-01-01').getTime() - new Date('1945-01-01').getTime())/31600800000 -> 69.90293916609706 . The 365.25 * 24 * 60 * 60 * 1000 that the resulting number should be divided by the number of milliseconds per year, and it can be recognized as a product of 365.25 * 24 * 60 * 60 * 1000 (we believe that we have the same year). - etki

1 answer 1

Why so difficult?

 d = nowdate.getFullYear() - 1945; 
  • And who will compare the date? The time in years is most likely the age ... - Qwertiy
  • Topstarter does not set the month and day. In this case, this solution is correct. - Oleksii Shapovalov