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?

213 questions
-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,045
  • 5
  • 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…
-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
  • 51
  • 1
  • 6
-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
  • 738
  • 2
  • 13
  • 29
-2
votes
1 answer

Vb.net: How do I end a loop with a specific string?

So I have to make a program that detects if it's a leap year or not. I already have the code for the leap year detector but the thing I'm having problems with is that after it has detected if it's a leap year or not, it is supposed to loop until I…
-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
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…
-3
votes
2 answers

Write a python function for leap year

Please help me with this code as it keeps giving "None" as output whenever a non leap year is input def is_leap(year): if year >=1900: if year%4==0: if year%100==0: if year%400==0: print ("True") …
Parth
  • 1
  • 2
-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
  • 6,646
  • 13
  • 29
  • 43
-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
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)); }
1 2 3
14
15