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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:41:19+00:00 2026-05-26T14:41:19+00:00

Some days ago, I have found a useful link in which a day on

  • 0

Some days ago, I have found a useful link in which a day on a given date is displayed. I found it very useful for embedding it into some specific applications. It works fine but on some dates, it does not work. Some of dates on which this formula does not work are as follows.

(dd/mm/yyyy)

1/3/1901

2/3/1901

3/3/1901

1/3/1902

2/3/1902

and so on…

The link where this formula was implemented in Javascript is as follows. Just follow it and try the above dates in three textfields given. It will display “undefined” means that it may not be specific to obtain the day on such dates. What should actually be the reason, any idea?

The relevant javascript code is:

var monthCodes = Array(5,1,1,4,6,2,4,0,3,5,1,3);
var weekdays = Array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
function compute() {
    d = conversion.day.value;
    m = conversion.month.value;
    y = conversion.year.value%100;
    c = Math.floor(conversion.year.value/100);
    if((conversion.year.value%4==0) && (conversion.year.value%100!=0 || conversion.year.value%400==0) && (m==1 || m==2))
        isLeapJanFeb = 1;
    else
        isLeapJanFeb = 0;
    weekday = (1*d + 1*monthCodes[m-1] + 1*y + 1*Math.floor(y/4) - 2*(c%4) - 1*isLeapJanFeb) % 7;
    alert(weekdays[weekday]);
}

Note that it works fine in Internet explorer. In some browsers like Mozilla Firefox, it may not work.

Here is the link…

http://katzentier.de/_misc/perpetual_calendar.htm

  • 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-26T14:41:19+00:00Added an answer on May 26, 2026 at 2:41 pm

    Well yes you found a bug in the JavaScript.

    I did a view source and copied it to a fiddle, but JSFiddle appears to be down now. Here is the code:

    var monthCodes = Array(5,1,1,4,6,2,4,0,3,5,1,3);
    var weekdays =['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
    var d = +prompt("Day");
    var m = +prompt("Month");
    var year = +prompt("Year");
    var y = year%100;
    var c = Math.floor(year/100);
    if ((year%4==0) && (year%100!=0 || year%400==0) && (m==1 || m==2))
        isLeapJanFeb = 1;
    else
        isLeapJanFeb = 0;
    weekday = Math.floor(1*d + 1*monthCodes[m-1] + 1*y + 1*Math.floor(y/4) - 2*(c%4) - 1*isLeapJanFeb) % 7;
    alert("Weekday code computed to be " + weekday);
    alert("The weekday is " + weekdays[weekday]);
    

    If you use today’s date it will work, but try 1 2 1901.

    The problem is that the computation gives -3, and -3 % 7 is -3 and when you index an array with -3 you get undefined.

    Maybe some browsers interpret a negative array index as something other than undefined. Perhaps their JS engine works like Ruby and for weekdays[-3] they count from the right end, because after all February 1, 1901 was indeed a Friday!

    Again, someone posted some bad code on the internet! Obligatory xkcd reference!

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

Sidebar

Related Questions

Some days ago I looked at boost sources and found interesting typedef . There
Some days ago I found a great project: vs-android. It allows you to build
I started out with Django some days ago and I have now made a
Some days ago I discovered a thing which is called the ASP.NET MVP framework
Some days ago, Someone ask me, If we have some agents in our environment,
I posted this question a few days ago, and I have some follow up
since some days ago I have a problem with VS2008 in a daily task.
Some days ago I was searching on the net and I found an interesting
Just some days ago I started looking into a unit test framework called check,
I have .NET assembly with ComVisible class. Some days ago (I can find that

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.