Question

There were many similar questions around but none addressed this calculation. Using javascript i it is easy to find the number of milliseconds diff b/w 2 dates for ex:

var mil = Math.floor(new Date("1/1/2012")  - new Date("1/7/2012"))

mil is assigned 518400000

to get weeks i would do below

var weeks = mil / (1000*7*24*60*60);

in the above example it exactly fits 1 week. For other possible inputs i would like to get output as ex:

n Weeks, y days , z hours

So i did mil % (1000*7*24*3600) to get the modulus and from the remainder calculate number of days. but astonishingly this was answer i got from console 1 weeks , 6 days seems the week calculated before is also accounted for days again.

How should i calculate these correctly?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top