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
1 answer

Java JodaTime - 29.02.2024 - Value 29 for dayOfMonth must be in the range [1,28] - leap year

I use this code in my application: final DateTime selectedDate = new DateTime().withMonthOfYear(month).withDayOfMonth(day).withYear(year); where month = 2, day = 29, year = 2024 and I get this exception: Value 29 for dayOfMonth must be in the range…
quma
  • 5,233
  • 26
  • 80
  • 146
3
votes
3 answers

leap year - by only using arithmetical operators in C

I have the weirdest exercise I've ever seen: I have to find a leap year by scanning a year in the console and to control if that is a leap year. I can only use + - / * % as arithmetical operators; I am not allowed to use any other operators or…
auroNpls
  • 49
  • 6
3
votes
3 answers

Accounting for leap year in comparing year to year sales

I am writing a program that shows the current years sales from the beginning of the fiscal year to the current date, compared to the same date range of the year before. My question is, what efforts do I need to take for leap year? UPDATE: OK they…
JD Isaacks
  • 56,088
  • 93
  • 276
  • 422
3
votes
4 answers

How to determine whether a year is a leap year in JavaScript

I'm trying to determine whether a year is a leap year or not. I'm not sure where i'm missing something because this code is meant to determine that. Thanks for your help. let Year = (year) => { this.year = year; }; Year.prototype.isLeap = () =>…
Mindsworth
  • 37
  • 2
  • 10
3
votes
4 answers

Regular expression for asp:RegularExpressionValidator with format MMddyy (leap year issue)

We need help for regular expression that work with asp.net asp:RegularExpressionValidator to validate date in MMddyy format. Problem we are facing is leap year. Issue is that is it possible to verify through regular expression that it only accepts…
Malik
  • 347
  • 1
  • 11
  • 29
3
votes
1 answer

Can I sychronize two highcharts series with different years (leap year)

The problem is best described in following fiddle: https://jsfiddle.net/bernhard_kern/85s2fm5a/3/. We use two series and two xAxis. xAxis: [{ type: 'datetime', min: new Date('2016/02/22').getTime(), max: new…
Bernhard Kern
  • 208
  • 2
  • 10
3
votes
2 answers

making php functions to count specific day

I have a function that calculate how many days in 1 year and I got it to work from Monday to Saturday by changing the $week variable from : Monday - 6:Saturday, but it will not work when I put 7: Sunday. can anyone help out. am I missing any…
Boby
  • 63
  • 1
  • 2
  • 11
3
votes
1 answer

Pandas date_range and leap years

When running this code: a = pd.date_range("1959-12-09 00:00:00", "2013-12-09 12:00:00", freq = "365D6H") weekDays = [dt.datetime.weekday(d) for d in a] df = pd.DataFrame({"Date": a, "Jour": weekDays}) df.head(6) I'm getting: 0 1959-12-09 00:00:00 …
user3166747
  • 284
  • 4
  • 11
3
votes
3 answers

SQL Server : birthdays on Leap Year

I have a table with employee birthdays. I'm trying to create a stored procedure that returns everyone's birthdays within 2 given dates. We have employees born on a leap year. I can successfully get return a person when their birthday falls on a leap…
RoLYroLLs
  • 3,113
  • 4
  • 38
  • 57
3
votes
6 answers

Q&A: How do I figure out what the last day of the month is?

I was trying to write a roll-your-own timezone converter and I needed a way of determining what the last possible day of the month was. Upon some research, I discovered the formulas for finding a leap year. It's a small contribution, but maybe I'll…
2
votes
3 answers

Javascript older than 18 on leap years

I'm using this javascript to check if the age entered is older than 18. function calculateDiffYear(date, month, year) { var cur = new Date(); var diff = Math.floor((cur.getTime() - new Date(year, month, date))…
K. Weber
  • 2,643
  • 5
  • 45
  • 77
2
votes
3 answers

Leap year solution check

I know there are better and more efficient solutions to check which year is a leap year. But I'm a beginner and I'm curious, despite my code being inefficient, does it still carry out the solution and its logic isn't flawed? This is how to work out…
Evgenii
  • 33
  • 4
2
votes
1 answer

How do I factor in leap years when determining the difference between two dates using Javascript?

I'm trying to set up a counter to determine the difference between a set past date and the current date. I have managed to set up a counter to determine the seconds between the two points, splitting the results into years, days, hours, minutes,…
Chris
  • 21
  • 1
2
votes
3 answers

To print value of the next leap year using variable in R programming

Question in R basic hands-on, Create a variable L, and assign the value of the year (2018) to it. Create another variable NL, assign the value of the next leap year using variable L, and then print NL." I have tried as below, But am not getting…
Gopal
  • 21
  • 1
  • 2
2
votes
1 answer

How to repeate the value of the last day of February for a leap year in R?

I have a data.frame that doesn't account for leap year (ie all years are 365 days). I would like to repeat the last day value in February during the leap year. The DF in my code below has fake data set, I intentionally remove the leap day value in…
Hydro
  • 1,057
  • 12
  • 25
1 2
3
16 17