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 8373775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:45:50+00:00 2026-06-09T14:45:50+00:00

Following is the code that calculates the week date, //Gets the week dayNumber date

  • 0

Following is the code that calculates the week date,

//Gets the week dayNumber date against the year,week number
var getWeekDate = function (year, weekNumber, dayNumber) {

var date = new Date(year, 0, 10, 0, 0, 0),
    day = new Date(year, 0, 4, 0, 0, 0),
    month = day.getTime() - date.getDay() * 86400000;
return new Date(month + ((weekNumber - 1) * 7 + dayNumber) * 86400000);
};

The code is working fine if I give the following values,

Input:
year = 2012
weekNumber = 1
dayNumber = 0 //My week starts from monday, so I am giving it 0.

Output:
2nd,Jan 2012 //That’s correct.

Input:
year = 2013
weekNumber = 1
dayNumber = 0 //My week starts from monday, so I am giving it 0.

Output:
31st,DEC 2012 //That’s in-correct.

The first week of 2013 will start from 7th, Jan 2013 i.e.Monday
but the above code is not calculating it 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-06-09T14:45:52+00:00Added an answer on June 9, 2026 at 2:45 pm

    That’s actually accurate because day zero (Monday) of week 1 of 2013 is still part of 2012. You could use a conditional to check whether the requested day of that week is part of the year.

    //Gets the week dayNumber date against the year,week number
    var getWeekDate = function (year, weekNumber, dayNumber) {
    
    var date = new Date(year, 0, 10, 0, 0, 0),
        day = new Date(year, 0, 4, 0, 0, 0),
        month = day.getTime() - date.getDay() * 86400000,
        ans = new Date(month + ((weekNumber - 1) * 7 + dayNumber) * 86400000);
    if (weekNumber === 1 && ans.getMonth() !== 0) {
        // We're still in last year... handle appropriately
    }
    return ans;
    };
    

    As an aside, it wouldn’t be a bad idea to put some variable checking in place. I can input week 0, week 55, and day 92 without any issues. Obviously the results are still accurate, but they may issue confusing results to those thinking in terms of calendars.

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

Sidebar

Related Questions

The following code calculates the previous week number from a given week when passed
I have the following code that gets the MAC address of an interface: static
Code The following code calculates the slope and intercept for a linear regression against
suppose that there is given following matlab code function dp = derp(p) n =
The following python code calculates the number of iterations to do stuff based on
I have the following code that has @item.ID from razor: <a href=# id=deleteitem(@item.ID)>Delete</a> When
I have the following code that opens a new popup window while disabling the
I have the following code that fails when i run it. my .h file:
I have the following code that returns a .CSV file when a link is
In the following code that skips comments, what's meaning of BEGIN(INITIAL) ? %x C_COMMENT

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.