+ Reply to Thread
Results 1 to 4 of 4

Function to retrurn true if at least one day between two dates is within desired month

  1. #1
    Registered User
    Join Date
    10-20-2014
    Location
    daventry,england
    MS-Off Ver
    2013
    Posts
    7

    Function to retrurn true if at least one day between two dates is within desired month

    Hi all,

    I need to come up with a function that would return TRUE if between start date and end date, there is at least one February day :

    e.g. Start date 01/01/2016 , End date 01/03/2016 -----> TRUE
    Start date 01/01/2016 , End date 31/01/2016 -----> False


    Thank you

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Function to retrurn true if at least one day between two dates is within desired month

    Try this...
    A
    B
    1
    1-Jan-16
    1-Jan-16
    2
    1-Mar-16
    31-Jan-16
    3
    TRUE
    FALSE

    A3=AND(2>=MONTH(A1),2<=MONTH(A2))
    copied across
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Function to retrurn true if at least one day between two dates is within desired month

    After testing with a friend at work I saw that my formula above will only work within the same year. As soon as you span years, i *can* fail.

    Try this instead....
    A
    B
    C
    1
    01/01/2016
    01/01/2016
    03/12/2015
    2
    03/01/2016
    01/31/2016
    05/05/2020
    3
    TRUE FALSE TRUE

    A3=AND(DATE(IF(AND(A1>DATE(YEAR(A1),2,1),A2>=DATE(YEAR(A2),2,28)),YEAR(A2),YEAR(A1)),2,1)>=A1,DATE(IF(AND(A1>DATE(YEAR(A1),2,1),A2>=DATE(YEAR(A2),2,28)),YEAR(A2),YEAR(A1)),2,28)<=A2)
    copied across

  4. #4
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Function to retrurn true if at least one day between two dates is within desired month

    OR,

    Try the following in C1:

    =IF(OR(OR(MONTH(A2)=2,MONTH(B2)=2),AND(MONTH(A2)<=1,MONTH(B2)>=2),AND(YEAR(B2)>YEAR(A2),MONTH(B2)>=2)),"TRUE","FALSE")

    See the attached file.
    Attached Files Attached Files
    Last edited by cbatrody; 12-14-2015 at 02:41 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 9
    Last Post: 10-08-2015, 01:50 PM
  2. EDATE function comparing dates returns true for same number month
    By jrodertogo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-04-2015, 04:19 AM
  3. [SOLVED] in this TRUE OR FALSE function, i want desired name instead of display true or false
    By vengatvj in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-15-2013, 06:44 PM
  4. [SOLVED] Subtracting MONTH Function from another MONTH Function not working for Fiscal dates
    By amartin575 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-16-2013, 10:52 AM
  5. [SOLVED] Averaging values if desired dates fall between range of dates
    By gbcpurdue in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2012, 02:51 PM
  6. Replies: 1
    Last Post: 08-03-2006, 08:25 AM
  7. [SOLVED] Function that compares dates and returns TRUE or FALSE
    By Emily in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-25-2006, 04:30 PM

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