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

Counting days of the year with leap years

I am currently trying to code this in R. I would like to take a date that I have in %Y-%m-%d (ex: 2017-12-31) format and convert it to the day of the year. However, I would like it to always count 02/28 as day #59 and 03/01 as day #61. When it is…
Sarah
  • 411
  • 4
  • 14
6
votes
1 answer

Oracle DB Ora-01839: date not valid for month specified. 29-02-2016 leap year

We all know today is a special day. Its the 29th of February 2016 of a leap year. We receive an error message from some tables in our Oracle DB. The error is:Oracle ORA-01839: date not valid for month specified. For example a simple select where…
Patrick
  • 12,336
  • 15
  • 73
  • 115
5
votes
1 answer

Finding out if its a leap year and setting accordingly

I have a form that has an initial end_date. I am having a Value error because this year is a leap year and we are currently in February. My code has a end day of 30 but I am having trouble figuring out how to write the code that will discover if…
TheLifeOfSteve
  • 3,208
  • 6
  • 37
  • 53
5
votes
3 answers

EntityFunctions.CreateDateTime issue with leap Year in linq to entity

When i have a leap year in my database (ex.: 29th Feb 2012). The EntityFunctions.CreateDateTime functions throws System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string. My Code is as follows in…
Prasad
  • 58,881
  • 64
  • 151
  • 199
5
votes
2 answers

Handling leap years in Python

I have a program where the user enters a date and then compares it to another date to see which one comes first. How would I go about writing a code where the user inputs Feb 29 and the program returns Feb 28 instead (since there is no leap…
python1
  • 51
  • 1
  • 1
  • 3
5
votes
6 answers

What calendar appears to count days since December 28, 1800?

I have been tasked to read in some data from some weird old system. The system contains many dates but they are all oddly formatted. They are integer numbers ranging from approximately 55,000 to 80,000. I know two dates for certain: 58,112 equals…
Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
5
votes
4 answers

mysql birthday reminder, leap year

I'm trying to sort out a result set that gives the 5 closest users sorted by upcoming birthday. This works perfectly until leap years comes into play. For example: May 15th - 96 days left May 15th - 97 days left The top result is a birth at 1987…
moodh
  • 2,661
  • 28
  • 42
5
votes
4 answers

Leap year calculation in C++ for Homework assignment?

#include using namespace std; int main() { int what_year; cout << "Enter calendar year "; cin >> what_year; if (what_year - (n * 4) = 0 ) { cout << "leap year"; } else { cout << "wont…
user1698658
  • 59
  • 1
  • 1
  • 2
4
votes
2 answers

Calculating a time duration with Joda-Time

I'm trying to use Joda-Time in order to know time durations between two points in time, where each point is given in its own local timezone. E.g. : DateTime ny = new DateTime(2011, 2, 2, 7, 0, 0, 0, DateTimeZone.forID("America/New_York")); DateTime…
bloodcell
  • 601
  • 1
  • 9
  • 23
4
votes
2 answers

Leap year and non leap year into separate tables

This code will display the the leap year and non leap year from 1991 to 2100, I tried to make table one for leap year and other for non leap year but I failed. How can I bring it in table format or in a grid system? This is for academic study. …
mishal
  • 63
  • 11
4
votes
2 answers

JS - Calculate number of days between 2 dates considering leap year

I want to calculate the number of days between 2 dates. Common problem. For exemple : var d0 = new Date("2016-02-27"); var d1 = new Date("2017-08-25"); Many people recommend using epoch difference : var res = (d1 - d0) / 1000 / 60 / 60 / 24; // res…
Liios
  • 93
  • 8
4
votes
7 answers

Leap Year Boolean Logic: Include Parentheses?

Which is "more correct (logically)"? Specific to Leap Year, not in general. With Parentheses return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) Without return year % 4 == 0 and year % 100 != 0 or year % 400 == 0 Additional…
JBallin
  • 8,481
  • 4
  • 46
  • 51
4
votes
1 answer

Why is my leap year algorithm not working (Java)?

Here is what I have: Scanner input = new Scanner(System.in); System.out.print("Enter a year: "); int Year = input.nextInt(); System.out.print("Enter a month (first three letters with the first" + " letter uppercase): "); …
P_Drach
  • 121
  • 6
4
votes
4 answers

How do I add 2 years to a date in powerbuilder and account for the leap year correctly?

How do I add 2 years to a date in powerbuilder and account for the leap year correctly? We have a medical license application where the user would like the date to go expire two years. Current license date is 7/10/2010 and expire date should be…
Judy
  • 75
  • 1
  • 2
  • 5
3
votes
3 answers

Mysql Dayofyear in leap year

In the following query the leap year is not taken into account. SELECT e.id, e.title, e.birthdate FROM employers e WHERE DAYOFYEAR(curdate()) <= DAYOFYEAR(e.birthdate) AND DAYOFYEAR(curdate())…
sanders
  • 10,794
  • 27
  • 85
  • 127
1
2
3
16 17