Consulting

Results 1 to 3 of 3

Thread: Check date is between 2 dates

  1. #1

    Check date is between 2 dates

    How can I check if a date falls within 2 dates.

    i.e.

    If 01/14/2011 is falls within 09/30/2010 and 10/01/2011 then
    msgbox "Yes"
    else
    Msgbox "No"

    Thanks for you help

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Aviator,

    Something like:
    [VBA]
    Option Explicit

    Sub example()
    Dim dtmMyDate As Date

    Const MIN_DATE = #9/30/2010#
    Const MAX_DATE = #10/1/2011#

    dtmMyDate = DateSerial(2011, 1, 14)
    If dtmMyDate > MIN_DATE And dtmMyDate < MAX_DATE Then
    MsgBox "Yep"
    Else
    MsgBox "Nope"
    End If
    End Sub
    [/VBA]

    Hope that helps,

    Mark

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    By formula, a simple

    =IF(AND(H2>=H3,H2<=H4),"Yes","No")
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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