Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- 411K Members
- 5,515 Online
- 466K Conversations

- Home
- :
- Excel
- :
- General Discussion
- :
- Leap year formula

Showing results for

Conversation Options

- Subscribe to RSS Feed
- Mark Conversation as New
- Mark Conversation as Read
- Pin this Conversation for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-19-2019 09:43 AM

Over the years I've run into several situations where we've needed to determine if the year is a leap year; most recently to determine the number of working days to calculate billable time - not the important part. I remember being taught as a kid the easy way to figure it out in your head but couldn't find a simple way to do in an Excel formula/cell.

**Figure out in your head:** I'm realizing a lot of the tricks I was shown as a kid may not be making it into the school system or are just lost arts of thinking...so I will share and hopefully you will learn something new as well.

Looking at positions 3 and 4 of the year is all you need to determine the leap year.

* Is position 3 odd or even?* (in 2019 this is the "1")

* Odd:* then only the last position of

* Even:* then the last positions of

Feel free to check me on any year....1944 - yep a leap year. 1972 - also a leap year. Knock yourself out.

**Excel formula**

*So even with this knowledge it is not easy to turn this into usable information in Excel...until this formula. It is applying the same logic above, into a single field formula.*

Spoiler

When you put it all together this is what it looks like.

=IF(MOD(MID(YEAR($A3),3,1),2)=0,IF(MOD(MID(YEAR($A3),4,1),4)=0,"Leap","No"),IF(OR(MID(YEAR($A3),4,1)="2",MID(YEAR($A3),4,1)="6"),"Leap","No"))

It can be a little confusing so let's break it down. Here is the pseudo syntax to help it all make sense:

- If the 3 position of the year is evenly divisible by 2 then A (even), else B (odd).
- A (even): If the 4th/last position of the year is evenly divisible by 4 then it is a leap year, if not it isn't a leap year.
- B (odd): If the last position of the year is either a 2 or a 6 then it is a leap year, if not it isn't a leap year.

Now that wasn't too hard...but it can be difficult and get lost in the formula.

So breaking down the formula to align with this pseudo code can help. We have to explain some of the values in our formula - so let's start with the assumption that

- our date is in cell
**A3**(I also have the $ reference in front of A as this is the column for all of my dates, but I'm going to copy this to multiple rows). - Let's also assume that we want to return the value of "Leap" for a leap year and "No" for any other year...we can then have other cells look for this reference without duplicating all of this logic through out your spreadsheet - one cell in each row for my situation.

**If the 3 position of the year is evenly divisible by 2 then A (even), else B (odd).**

=IF(MOD(MID(YEAR($A3),3,1),2)=0, {EVEN},{ODD})

Now the sub if statements

**A (even): If the 4th/last position of the year is evenly divisible by 4 then it is a leap year, if not it isn't a leap year.**

IF(MOD(MID(YEAR($A3),4,1),4)=0,"Leap","No"

**B (odd): If the last position of the year is either a 2 or a 6 then it is a leap year, if not it isn't a leap year.**

IF(OR(MID(YEAR($A3),4,1)="2",MID(YEAR($A3),4,1)="6"),"Leap","No"

When you put it all together this is what it looks like.

=IF(MOD(MID(YEAR($A3),3,1),2)=0,IF(MOD(MID(YEAR($A3),4,1),4)=0,"Leap","No"),IF(OR(MID(YEAR($A3),4,1)="2",MID(YEAR($A3),4,1)="6"),"Leap","No"))

I hope this helps or gives you ideas for other problems you can solve.

Labels:

4 Replies

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-19-2019 10:01 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-19-2019 11:04 AM

Another alternative is:

=IF(DAY(DATE(YEAR(A1),3,0))=29,

“Leap”,”No”)

=IF(DAY(DATE(YEAR(A1),3,0))=29,

“Leap”,”No”)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-19-2019 12:38 PM

@Sergei Baklan Well...if you want to do it the easy way I guess you could do that...doesn't have as good of a story.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-19-2019 01:01 PM

Story is great, but in coding I prefer to keep things simple

Related Conversations

flashing a white screen while open new tab

cntvertex
in
Discussions
on
10-05-2019
23.2K
Views

10 Likes

13 Replies

Stable version of Edge insider browser

HotCakeX
in
Discussions
on
10-12-2019
24.7K
Views

1 Likes

35 Replies

What is Canary ring in Windows insider program? and how do we get them?

HotCakeX
in
Windows Insider Program
on
09-27-2019
11.1K
Views

0 Likes

9 Replies

How to Prevent Teams from Auto-Launch

chenrylee
in
Microsoft Teams
on
06-27-2019
137K
Views

6 Likes

28 Replies

PacketMon Components are not loading in WAC 1909

HotCakeX
in
Windows Admin Center
on
09-24-2019
1,659
Views

0 Likes

2 Replies

Share

Popular

Learning Resources

Programs

Values

- Contact us
- Privacy & cookies
- Terms of use
- Trademarks
- About our ads
- © Microsoft