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
-3
votes
2 answers

How to solve this Multiple Branching question

Create function is_leap_year(y) in which y is a year number. the function will return True if the year is a leap year, otherwise, it will return False. A leap year's number is an integer multiple of 4 (except for years evenly divisible by 100, which…
-3
votes
1 answer

Why doesn't this work? It has a problem with the first if statement

def YearType(year): leapyear = False year = int(year) if year MOD 4 == 0 or year MOD 400 == 0: leapyear = True elif (year MOD 100 == 0): leapyear = False elif leapyear == True: print("wow this year is…
-3
votes
1 answer

Why is my leap year code not working? (Specially int day)

Alright so this is a code from Jupyterlab. And i wanted to know why the int day wont respond to the changes made to the value? The code conering starts from line 37 at //day (January). #include int main() { int year = 2021; …
-3
votes
3 answers

Return list of True/ False bool value for list of leap years given as an argument

I have to check whether year = [1900, 2020, 2021, 2001] is a leap year or not and get True/False as a result (Boolean) I have written a function as : def is_leap_year(year): return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) But now I…
Tanvi
  • 69
  • 6
-3
votes
2 answers

correct my Python leap year code as per below conditions

The year can be evenly divided by 4, is a leap year, unless: The year can be evenly divided by 100, it is NOT a leap year, unless: The year is also evenly divisible by 400. Then it is a leap year. Please correct my code. I'm not looking for…
Chaitanya Chitturi
  • 1,129
  • 2
  • 7
  • 8
-3
votes
2 answers

conversion of a varchar data type to a datetime data type resulted in an out-of-range value: ONLY for leap year day

I am trying to insert date into a datetime column after formatting getdate() tovarchar(8) using convert function. I see it works for most part but incidentally when date is leap date(29th feb) it fails with conversion of varchar to datetime error. I…
-3
votes
1 answer

typeError: unsupported operand type(s) for %: 'list' and 'int'

I am trying to determine if these years are leap years. 1900, 1999, 2000, 2001,2002,2003,2004 def leapyr(n): if (n%4==0) and (n%100!=0): if (n%400==0): print (n, " is a leap year.") elif (year%4!=0): print (n, "…
Sean B
  • 1
  • 5
-3
votes
2 answers

Java Leap Year Calculator

I am making a scanner object to get a year and test to see if it is a leap year. Just want some feedback. Is this right what I have? Thank you! import java.util.Scanner; public class Micro4 { public static void main(String[] args) { …
Rafael
  • 7,605
  • 13
  • 31
  • 46
-3
votes
1 answer

How do you count the number of days between two dates excluding the extra day in leap years

In the picture I count the number of days between two dates excluding the extra day of the leap years. How can this be done in SQL Server 2008 R2?
g2_player
  • 49
  • 1
  • 9
-4
votes
1 answer

Jquery datepicker showing wrong date for leap year

I am using a date-picker in an old project and it is working fine but it displayed wrong date for leap year for 29/02/2016. This is displaying 01/03/2016 instead of 29/02/2016. Please help me for displaying proper date of leap year. Visit: …
user3603284
  • 43
  • 1
  • 13
-5
votes
3 answers

A leap year determining C program is not giving any output when inputting 2000, 1900 or 2100 as an input

When I am running this C program, and giving 2020, 2024 or other years perfectly divisible by 4, then I am getting expected output i.e. it is a leap year. But when I am giving a century year : 1900, 2000 or 2100 etc. as an input, then it's not not…
-5
votes
1 answer

Could you explain what is happening in this code?

Please explain what is happening in the code. I tried the if else that did not work. #include int isLeapYear(int year) { return ((!(year % 4) && year % 100) || !(year % 400)); }
-6
votes
1 answer

Leap Year Calculations using Method

import java.util.Scanner; public class LeapYearTester{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Please enter a year"); int year_input = input.nextInt(); // now…
Kukie
  • 1
  • 1
-7
votes
2 answers

Add years, months and days to date C

I am trying to write an algorithm that takes an input of a date ("2000-01-01") and also "y|m|d", where y is the number of years to add to the original date and m and d are the months and days. This algorithm needs to take into account leap years as…
Jamie1596
  • 104
  • 1
  • 1
  • 11
-9
votes
2 answers

Is there a simpler test for leap year in C?

Is there any shorter logic than this to achieve leap year test with fewer conditions? #include int isleap(int year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } int main() { for (int year = 1600; year…
roh.it
  • 23
  • 1
  • 7
1 2 3
16
17