+ Reply to Thread
Results 1 to 5 of 5

Formulate LEAP yr to be 365 days in excel

  1. #1
    Registered User
    Join Date
    05-11-2012
    Location
    Si Hui Lee
    MS-Off Ver
    Excel 2010
    Posts
    4

    Formulate LEAP yr to be 365 days in excel

    I am suppose to calculate the days between 2 dates. However, leap yr would be 366 days but i have to formulate it so that no matter whether its leap yr or not, no. of days would be 365. So I would need to exclude 29 feb from every leap yr.

    I've tried using the formula I found in another forum:
    =SUMPRODUCT(--(TEXT(ROW(INDIRECT(F4+1&":"&F5)),"dd-mmm")<>"29-feb"))
    but when I input 01/01/2007 and 31/12/2007, the no. of days reflected was 364 days.
    and when I input 01/01/2008 and 31/12/2008, the no. of days reflected was 364 days too. I have no idea what went wrong.

    Anyone have any advise for me? Or any formula to recommend???
    Need lots of help for Excel!!! Thanks in advance!

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Formulate LEAP yr to be 365 days in excel

    You don't add 1 to the start date

    =SUMPRODUCT(--(TEXT(ROW(INDIRECT(F4&":"&F5)),"dd-mmm")<>"29-feb"))

    You need to be inclusive.

  3. #3
    Registered User
    Join Date
    05-11-2012
    Location
    Si Hui Lee
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Formulate LEAP yr to be 365 days in excel

    Quote Originally Posted by Bob Phillips View Post
    You don't add 1 to the start date

    =SUMPRODUCT(--(TEXT(ROW(INDIRECT(F4&":"&F5)),"dd-mmm")<>"29-feb"))

    You need to be inclusive.
    thanks sooooo much! issue solved. but is it possible to explain how does the formula works? like the "text", "row" etc.

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Formulate LEAP yr to be 365 days in excel

    The F4&":"F5 starts by creating a range string based upon the start (1st Jan 2007) and end dates (31st Jan 2007). In your example it equates to "39083:39447"

    INDIRECTing this string creates a reference to that range, and ROW(INDIRECT(F4&":"F5)) creates an array of the row numbers within that range, {39083;39084;39085;39086;39087;39088;...;39447}. This has the effect of creating an array of all of the dates between start date and end date, which the formula can now check.

    Using the TEXT function on this, TEXT(ROW(INDIRECT(F4&":"F5)),"dd-mmm") creates an array of those dates in this format {"01-Jan";"02-Jan";"03-Jan";"04-Jan";"05-Jan";"06-Jan";"07-Jan";"08-Jan";...;"31-Dec"}

    This array is then compared against the string for 29-Feb, TEXT(ROW(INDIRECT(F4&":"F5)),"dd-mmm")="29-feb", which returns an array of TRUE/FALSE for all of those dates. Every value will be TRUE, except for the one of 29th Feb (if there is a 29th Feb).

    The last but one step coerces this array of TRUE/FALSE to an array of 1/0 --(TEXT(ROW(INDIRECT(F4&":"F5)),"dd-mmm")), and finally SUMPRODUCT adds up all of those 1 and 0's to calculate the number of days between those two dates that are not 29th Feb.
    Last edited by Bob Phillips; 05-12-2012 at 10:41 AM.

  5. #5
    Registered User
    Join Date
    05-11-2012
    Location
    Si Hui Lee
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Formulate LEAP yr to be 365 days in excel

    thx a lot Bob! understood the formula. shall play around with. Thanks agn!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1