Home

Leap year formula

%3CLINGO-SUB%20id%3D%22lingo-sub-863597%22%20slang%3D%22en-US%22%3ELeap%20year%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-863597%22%20slang%3D%22en-US%22%3E%3CP%3EOver%20the%20years%20I've%20run%20into%20several%20situations%20where%20we've%20needed%20to%20determine%20if%20the%20year%20is%20a%20leap%20year%3B%20most%20recently%20to%20determine%20the%20number%20of%20working%20days%20to%20calculate%20billable%20time%20-%20not%20the%20important%20part.%26nbsp%3B%20I%20remember%20being%20taught%20as%20a%20kid%20the%20easy%20way%20to%20figure%20it%20out%20in%20your%20head%20but%20couldn't%20find%20a%20simple%20way%20to%20do%20in%20an%20Excel%20formula%2Fcell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EFigure%20out%20in%20your%20head%3A%3C%2FSTRONG%3E%26nbsp%3B%20I'm%20realizing%20a%20lot%20of%20the%20tricks%20I%20was%20shown%20as%20a%20kid%20may%20not%20be%20making%20it%20into%20the%20school%20system%20or%20are%20just%20lost%20arts%20of%20thinking...so%20I%20will%20share%20and%20hopefully%20you%20will%20learn%20something%20new%20as%20well.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3ELooking%20at%20positions%203%20and%204%20of%20the%20year%20is%20all%20you%20need%20to%20determine%20the%20leap%20year.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EIs%20position%203%20odd%20or%20even%3F%3C%2FSTRONG%3E%3C%2FEM%3E%26nbsp%3B(in%202019%20this%20is%20the%20%221%22)%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EOdd%3A%3C%2FSTRONG%3E%3C%2FEM%3E%20then%20only%20the%20last%20position%20of%20%3CSTRONG%3E%222%22%20or%20%226%22%3C%2FSTRONG%3E%20are%20a%20leap%20year.%26nbsp%3B%20So%202012%20and%202016%20were%20leap%20years.%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EEven%3A%3C%2FSTRONG%3E%3C%2FEM%3E%20then%20the%20last%20positions%20of%20%3CSTRONG%3E%220%22%2C%20%224%22%20or%20%228%22%3C%2FSTRONG%3E%20are%20leap%20years.%20So%202002%2C%202004%2C%202008%20were%20all%20leap%20years.%3C%2FP%3E%3CP%3EFeel%20free%20to%20check%20me%20on%20any%20year....1944%20-%20yep%20a%20leap%20year.%26nbsp%3B%201972%20-%20also%20a%20leap%20year.%26nbsp%3B%20Knock%20yourself%20out.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EExcel%20formula%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CEM%3ESo%20even%20with%20this%20knowledge%20it%20is%20not%20easy%20to%20turn%20this%20into%20usable%20information%20in%20Excel...until%20this%20formula.%26nbsp%3B%20It%20is%20applying%20the%20same%20logic%20above%2C%20into%20a%20single%20field%20formula.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESpoiler%3C%2FA%3E%3CNOSCRIPT%3E(Highlight%20to%20read)%3C%2FNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-border%22%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3E%3CP%3EWhen%20you%20put%20it%20all%20together%20this%20is%20what%20it%20looks%20like.%3C%2FP%3E%3CP%3E%3DIF(MOD(MID(YEAR(%24A3)%2C3%2C1)%2C2)%3D0%2CIF(MOD(MID(YEAR(%24A3)%2C4%2C1)%2C4)%3D0%2C%22Leap%22%2C%22No%22)%2CIF(OR(MID(YEAR(%24A3)%2C4%2C1)%3D%222%22%2CMID(YEAR(%24A3)%2C4%2C1)%3D%226%22)%2C%22Leap%22%2C%22No%22))%3C%2FP%3E%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-container%22%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3EWhen%20you%20put%20it%20all%20together%20this%20is%20what%20it%20looks%20like.%3DIF(MOD(MID(YEAR(%24A3)%2C3%2C1)%2C2)%3D0%2CIF(MOD(MID(YEAR(%24A3)%2C4%2C1)%2C4)%3D0%2C%22Leap%22%2C%22No%22)%2CIF(OR(MID(YEAR(%24A3)%2C4%2C1)%3D%222%22%2CMID(YEAR(%24A3)%2C4%2C1)%3D%226%22)%2C%22Leap%22%2C%22No%22))%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20can%20be%20a%20little%20confusing%20so%20let's%20break%20it%20down.%26nbsp%3B%20Here%20is%20the%20pseudo%20syntax%20to%20help%20it%20all%20make%20sense%3A%3C%2FP%3E%3COL%3E%3CLI%3EIf%20the%203%20position%20of%20the%20year%20is%20evenly%20divisible%20by%202%20then%20A%20(even)%2C%20else%20B%20(odd).%3C%2FLI%3E%3CLI%3EA%20(even)%3A%20If%20the%204th%2Flast%20position%20of%20the%20year%20is%20evenly%20divisible%20by%204%20then%20it%20is%20a%20leap%20year%2C%20if%20not%20it%20isn't%20a%20leap%20year.%3C%2FLI%3E%3CLI%3EB%20(odd)%3A%20If%20the%20last%20position%20of%20the%20year%20is%20either%20a%202%20or%20a%206%20then%20it%20is%20a%20leap%20year%2C%20if%20not%20it%20isn't%20a%20leap%20year.%3C%2FLI%3E%3C%2FOL%3E%3CP%3ENow%20that%20wasn't%20too%20hard...but%20it%20can%20be%20difficult%20and%20get%20lost%20in%20the%20formula.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20breaking%20down%20the%20formula%20to%20align%20with%20this%20pseudo%20code%20can%20help.%26nbsp%3B%20We%20have%20to%20explain%20some%20of%20the%20values%20in%20our%20formula%20-%20so%20let's%20start%20with%20the%20assumption%20that%3C%2FP%3E%3COL%3E%3CLI%3Eour%20date%20is%20in%20cell%20%3CSTRONG%3EA3%3C%2FSTRONG%3E%20(I%20also%20have%20the%20%24%20reference%20in%20front%20of%20A%20as%20this%20is%20the%20column%20for%20all%20of%20my%20dates%2C%20but%20I'm%20going%20to%20copy%20this%20to%20multiple%20rows).%26nbsp%3B%3C%2FLI%3E%3CLI%3ELet's%20also%20assume%20that%20we%20want%20to%20return%20the%20value%20of%20%22Leap%22%20for%20a%20leap%20year%20and%20%22No%22%20for%20any%20other%20year...we%20can%20then%20have%20other%20cells%20look%20for%20this%20reference%20without%20duplicating%20all%20of%20this%20logic%20through%20out%20your%20spreadsheet%20-%20one%20cell%20in%20each%20row%20for%20my%20situation.%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3CEM%3E%3CSTRONG%3EIf%20the%203%20position%20of%20the%20year%20is%20evenly%20divisible%20by%202%20then%20A%20(even)%2C%20else%20B%20(odd).%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3DIF(MOD(MID(YEAR(%24A3)%2C3%2C1)%2C2)%3D0%2C%20%7BEVEN%7D%2C%7BODD%7D)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20the%20sub%20if%20statements%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EA%20(even)%3A%20If%20the%204th%2Flast%20position%20of%20the%20year%20is%20evenly%20divisible%20by%204%20then%20it%20is%20a%20leap%20year%2C%20if%20not%20it%20isn't%20a%20leap%20year.%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3EIF(MOD(MID(YEAR(%24A3)%2C4%2C1)%2C4)%3D0%2C%22Leap%22%2C%22No%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EB%20(odd)%3A%20If%20the%20last%20position%20of%20the%20year%20is%20either%20a%202%20or%20a%206%20then%20it%20is%20a%20leap%20year%2C%20if%20not%20it%20isn't%20a%20leap%20year.%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3EIF(OR(MID(YEAR(%24A3)%2C4%2C1)%3D%222%22%2CMID(YEAR(%24A3)%2C4%2C1)%3D%226%22)%2C%22Leap%22%2C%22No%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20you%20put%20it%20all%20together%20this%20is%20what%20it%20looks%20like.%3C%2FP%3E%3CP%3E%3DIF(MOD(MID(YEAR(%24A3)%2C3%2C1)%2C2)%3D0%2CIF(MOD(MID(YEAR(%24A3)%2C4%2C1)%2C4)%3D0%2C%22Leap%22%2C%22No%22)%2CIF(OR(MID(YEAR(%24A3)%2C4%2C1)%3D%222%22%2CMID(YEAR(%24A3)%2C4%2C1)%3D%226%22)%2C%22Leap%22%2C%22No%22))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20helps%20or%20gives%20you%20ideas%20for%20other%20problems%20you%20can%20solve.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-863597%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eformula%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ein%20cell%20calculation%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eleap%20year%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-863609%22%20slang%3D%22en-US%22%3ERe%3A%20Leap%20year%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-863609%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F411938%22%20target%3D%22_blank%22%3E%40Hattsoff%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBit%20more%20simple%20variant%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3DIF(MONTH(DATE(YEAR(A1)%2C2%2C29))%3D2%2C%22Leap%22%2C%22No%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-863722%22%20slang%3D%22en-US%22%3ERe%3A%20Leap%20year%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-863722%22%20slang%3D%22en-US%22%3EAnother%20alternative%20is%3A%3CBR%20%2F%3E%3DIF(DAY(DATE(YEAR(A1)%2C3%2C0))%3D29%2C%3CBR%20%2F%3E%E2%80%9CLeap%E2%80%9D%2C%E2%80%9DNo%E2%80%9D)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-863935%22%20slang%3D%22en-US%22%3ERe%3A%20Leap%20year%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-863935%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3BWell...if%20you%20want%20to%20do%20it%20the%20easy%20way%20I%20guess%20you%20could%20do%20that...doesn't%20have%20as%20good%20of%20a%20story.%26nbsp%3B%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-863953%22%20slang%3D%22en-US%22%3ERe%3A%20Leap%20year%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-863953%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F411938%22%20target%3D%22_blank%22%3E%40Hattsoff%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStory%20is%20great%2C%20but%20in%20coding%26nbsp%3B%20I%20prefer%20to%20keep%20things%20simple%3C%2FP%3E%3C%2FLINGO-BODY%3E
Hattsoff
New Contributor

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 "2" or "6" are a leap year.  So 2012 and 2016 were leap years.

Even: then the last positions of "0", "4" or "8" are leap years. So 2002, 2004, 2008 were all leap years.

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:

  1. If the 3 position of the year is evenly divisible by 2 then A (even), else B (odd).
  2. 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.
  3. 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

  1. 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). 
  2. 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.

 

4 Replies

@Hattsoff 

Bit more simple variant

=IF(MONTH(DATE(YEAR(A1),2,29))=2,"Leap","No")

 

Another alternative is:
=IF(DAY(DATE(YEAR(A1),3,0))=29,
“Leap”,”No”)

@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. 

@Hattsoff 

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

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
PacketMon Components are not loading in WAC 1909
HotCakeX in Windows Admin Center on
2 Replies