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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:23:26+00:00 2026-06-17T13:23:26+00:00

I wrote a calendar in javascript and jquery (adapted from Simple Calendar with Javascript

  • 0

I wrote a calendar in javascript and jquery (adapted from “Simple Calendar with Javascript”) that allows me to move back and forward months at a time.

It accounts for leap years by adding in an extra day every 4 years in February, but it seems that an error is being caused because of this.

When you move back in time, or forward, it changes the date and runs the calendar() function according to the new date. Normally, it has 5 rows with 7 columns, each column containing a day. If there isn’t enough room with the 5 rows, such as there being 31 days with the 1st being on a Saturday, then it will add an extra 6th row to accommodate.

During a leap year, however, the function doesn’t seem to add the extra rows in if the same scenario above happens.

Here’s a jsFiddle: http://jsfiddle.net/charlescarver/DrMWM/

This gist of calendar():

function calendar(d){

                $("#calendar").remove();
                $("body").append("<table border='1' id='calendar'></table>");

                // Date vars
                var today = new Date(d);
                var month = today.getMonth();
                var day = today.getDay();
                var dayN = today.getDate();
                var week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                var monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
                var days = monthdays[month];
                var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

                // Determine if leap year, if not, set to current year
                if (month > 0) {
                    year = today.getYear();
                    if (year % 4 == 0){
                        days = 29;
                    }
                } else {
                    year = today.getYear();
                }

                // Parse vars
                var jumped = 0;
                var inserted = 1;
                var start = day - dayN%7 + 1;
                if (start < 0) start += 7;
                var weeks = parseInt((start + days)/7);
                if ((start + days)%7 != 0){
                    weeks++;
                }

                $("#calendar").append("<tr><td class='month' colspan='7'>" + monthNames[month] + " - " + today.getFullYear() + "</td></tr>");

                $("#calendar").append("<tr class='day'></tr>");
                for (var i=0; i<7; i++) {
                    $(".day").append("<td>" + week[i][0] + "</td>");
                }

                function datDate(m, n, y){
                    date = new Date(" " + monthNames[m] + " " + n + " " + y);
                    return date;
                }

                for (var i=weeks; i>0; i--) {
                    if (i === i){
                        $("#calendar").append("<tr class=" + i + "></tr>");
                        for (var j=0; j<7; j++) {
                            console.log(inserted);
                            if (jumped<start || inserted>days) {
                                $("." + i).append("<td> </td>");
                                jumped++;
                            }
                            else {
                                m = month;
                                n = inserted;
                                y = today.getFullYear();
                                date = datDate(m, n, y);
                                if (inserted == dayN) {
                                    $("." + i).append("<td><a class='calendar_date current_date' data-date='" + date + "'>[" + n + "]</a></td>");
                                } else {
                                    $("." + i).append("<td><a class='calendar_date' data-date='" + date + "'>" + n + "</a></td>");
                                }
                                inserted++;
                            }
                        }
                    }
                }   
            }
  • 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-17T13:23:27+00:00Added an answer on June 17, 2026 at 1:23 pm
                // Determine if leap year, if not, set to current year
                if (month == 1) {
                    year = today.getYear();
                    if (year % 4 == 0){
                        days = 29;
                    }
                } else {
                    year = today.getYear();
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote simple code for deleting all entries from android calendar,but it didn't delete
I have a schedule/calendar app that I wrote in Rails that I'm rewriting using
I wrote the following javascript to dynamically build a calendar and append it to
I need to compare two calendar dates. I wrote the javascript function too. But
Say I wanted to write a program that would export calendar data so that
Is there a way to write in the standard calendar from the smartphone from
I wrote a simple XML file and a DTD file including an entity, but
javascript newbie here, I wrote a form in html and submitted it with an
I've been hunting for a long time for this, but despite my intuition that
I wrote the following code to get the time public String getTime() { final

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.