Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:15:38+00:00 2026-05-30T06:15:38+00:00

There were many similar questions around but none addressed this calculation. Using javascript i

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:15:39+00:00Added an answer on May 30, 2026 at 6:15 am
    var seconds = (mil / 1000) | 0;
    mil -= seconds * 1000;
    
    var minutes = (seconds / 60) | 0;
    seconds -= minutes * 60;
    
    var hours = (minutes / 60) | 0;
    minutes -= hours * 60;
    
    var days = (hours / 24) | 0;
    hours -= days * 24;
    
    var weeks = (days / 7) | 0;
    days -= weeks * 7;
    

    Assuming mils is non-negative, this leaves mils in the range [0, 1000), leaves minutes and seconds in the range [0, 60), leaves hours in the range [0, 24), and leaves days in the range [0, 7).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many similar questions, but nothing that answers this specifically after googling around
Remark : I know there are many similar questions on SO, but none specific
there are similar questions but not clear answer around using sqlite db from multiple
There are many similar questions, but I couldn't find exactly how to use a
First things first, there are many questions similar to this, I know, but I
There are many similar questions, but apparently no perfect match, that's why I'm asking.
Disclaimer: there are many similar questions on SO, but I am looking for a
I know that there are many similar questions, but I don't understand most of
I've looked around the current answers for similar questions but still couldn't find the
There are many similar questions, but I've tried about 15 different preg_match examples and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.