Questions tagged [leap-year]

A leap year is a year containing one additional day, which falls on Feb 29 in the Gregorian calendar.

A leap year (or intercalary or bissextile year) is a year containing one additional day in order to keep the calendar year synchronized with the astronomical or seasonal year.

Because seasons and astronomical events do not repeat in a whole number of days, calendars that have the same number of days in each year, over time, drift with respect to the event that the year is supposed to track. By inserting (or intercalating) an additional day or month into the year, the drift can be corrected. A year that is not a leap year is called a common year.

More about leap years in general are on Wikipedia here.

In computing, we usually are usually referring to the Gregorian Calendar, which inserts an additional day on February 29th into a leap year. A leap year is a year which satisfies both of the following criteria:

  • It is evenly divisible by 4.
  • It is not evenly divisible by 100 unless it is also evenly divisible by 400.

A common implementation of this algorithm is:

bool isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);

Leap Year Bugs

Leap years can create bugs in software. This is described in the following post:

What are some examples of leap year bugs?

255 questions
-1
votes
3 answers

how to find out number of leap years if you have entered date and some x seconds to add

So let me explain: On input u got: e.g.: 5 7 1904 5 5 5 675876789 day,month,year hours,mins,secs and some number k. At the output you need to get: 4.12.1925. 20:38:14 I'm constantly getting 5.12.1925 20:38:14 just because of leap years and my…
Vinko Vorih
  • 31
  • 1
  • 3
-1
votes
1 answer

Age calculation leap year issue in php

I am using following function to calculate age from given date of birth, but its not showing the correct difference if a leap year day i.e 29 is used. Please help me fix this code.
Asnexplore
  • 363
  • 1
  • 7
  • 25
-2
votes
1 answer

Leap Year Messing up Future Date Calculations

So My coworker and I have been in the works on creating a Blazor app for an expiration date calculator for the labs at our company. We are basically almost done until we realized that leap years exist and are messing up the calculation. We know how…
Sahar
  • 13
  • 5
-2
votes
1 answer

How to add printing of number of days in a year also for leap years?

I am having trouble adding it so that my program prints out the days in a certain year. What's messing me up is the leap years. Don't want to scrap it. I am confused and was trying to put it together by myself and should have asked for help. wanted…
wonder_9
  • 1
  • 5
-2
votes
1 answer

How can we match the length of the Gregorian year and the length of the tropical year?

At present the average length of the Gregorian Year over a period of 400 years is 365.2425 days, calculated as follows. Average length of the Gregorian Year = (97 x 366 + 303 x 365)/ 400 = 365.2425 days Since the length of the Tropical year is 365…
-2
votes
1 answer

Why is this code to calculate a leap year with javascript correct?

I wrote this code for calculating a leap year in JavaScript and apparently it's correct but I don't understand why, because it seems logical to me to say: if(year%400===0).... but it's incorrect if I do that why?? code: function isLeap(year) { …
ivanka
  • 1
-2
votes
3 answers

How Display Month which is Start with Current Month Using PHP?

I want to display all month with current year but it must be start with current month like below. I need like if current month October and year 2019 then option list should be start with 2019-10 then all renaming month with current year like below.…
Vaibhavi S.
  • 1,083
  • 7
  • 20
-2
votes
1 answer

C++ program for checking whether the input is a leap year

I am Tony and I am new to c++ programming. I would like to ask a question related to creating a program to check for leap year. In the following codes, I try to create a bool function to check whether the input is a leap year. If the input is…
-2
votes
3 answers

Find the next leap year in C

I'm having trouble with an exercise on my homework. I have to make a function that tells me when the next leap year is given an n (or n if it's a leap year). I already tackled the last part, but I'm having trouble with the "next leap year" part. I…
Tiago Araújo
  • 19
  • 1
  • 6
-2
votes
1 answer

Proving that this code is finding if the year is a leap year

I have to write a code that tells me if a specific year of the gregorian calendar is leap year. However I'm not sure that the code will work for every every year. It works for 1900, 1901, 2000. Before I paste the code, maybe you should know what…
TierOne
  • 61
  • 1
  • 8
-2
votes
3 answers

Javascript calculate same weekday next year

I have some trouble to calculate the weekday of a given date next year. For example: Tuesday, 19. April 2016 is the given date. Now I would calculate: TUESDAY, 18. April 2017. It is very important that the weekdays are always the same. My problem…
Patrick Vogt
  • 898
  • 2
  • 14
  • 33
-2
votes
1 answer

php - mySQL select date week for year

I have 1 column contains the date format date: 2013-09-22 2013-09-23 2013-09-24 2013-09-25 2013-09-26 2013-09-27 2013-09-28 2013-09-29 2013-09-30 2013-10-01 2013-10-02 Today is the 40th week of the year. I want to select all days have 40 weeks to do…
-3
votes
3 answers

Can anyone tell me what is wrong with my code? One test case is failing

def is_leap(year): leap = False # Write your logic here if year%4==0: return True elif year%400==0: return True elif year%100 != 0: return False else: return False return leap year =…
-3
votes
1 answer

Convert milliseconds to years accurately, with decimal, in Javascript?

I'm trying to build an application similar to this. What it does is gives you the time since a specific date in years, with about 10-15 decimal places. I already took a look at this post, but every answer either didn't account for leap years, or…
John Smith
  • 81
  • 7
-3
votes
1 answer

For a leap-year check, why check if the year is not divisible by 100?

What my understanding is like: for a year its like 365.2425 to be precise so if we take for a year (365.24 ) it leaves .24 days right it is like 6 hrs for every 4 years it adds up to 24 hrs so it will create a day we add this to feb 29 so why we…
1 2 3
16
17