how to trap dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nurikoAnna
    New Member
    • Nov 2008
    • 26

    how to trap dates

    how to trap dates within a 1 year gap

    Example:

    From: 2008 To: 2010


    it will prompt an error because it should be 2009 ...1 year gap...

    what are the codes for that.....please ...

    I am having a hard time on that
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    Please can you provide more information and code if possible as you have not really given enough information to work out what on earth you are talking about :)

    How are the addresses being 'selected' are users entering them into a free text box or selecting from a calendar or dropdown?

    Comment

    • !NoItAll
      Contributor
      • May 2006
      • 297

      #3
      There really isn't enough information for anyone to help you meaningfully. Chances are any suggestions that come from your question will not likely be what you want.
      Here's a quick stab - or at least a place to start:
      Put this code in a button called Command1

      Code:
      Private Sub Command1_Click()
      Dim dDate1 As Date
      Dim dDate2 As Date
      Dim lSpan As Long
      Dim iYearLength As Integer
      
      'you can assign the dates however you want
      dDate1 = "1/1/2006"
      dDate2 = "1/2/2007"
      
      lSpan = DateDiff("d", dDate1, dDate2)
      
      'we need to know if either of the years are leap years because we are counting 'days
      If isLeapYear(year(dDate1)) Or isLeapYear(year(dDate2)) Then
          iYearLength = 366
      Else
          iYearLength = 365
      End If
      
      If lSpan > iYearLength Then
      
          MsgBox "Gap is more than one year!"
      
      ElseIf lSpan < iYearLength Then
      
          MsgBox "Gap is less than one year!"
      
      Else
      
          MsgBox "Gap is EXACTLY one year!"
          
      End If
      
      End Sub
      
      
      Function isLeapYear(year As Integer) As Boolean
      
      
          If (year Mod 4 = 0 And year Mod 100 <> 0) Or year Mod 400 = 0 Then
      
              isLeapYear = True
      
          Else
      
              isLeapYear = False
      
          End If
      
      End Function
      You can get very granular if you want - down to the hour or minute.

      Comment

      • smartchap
        New Member
        • Dec 2007
        • 236

        #4
        For the exact answer you are expecting please post the code along with the error you are getting so that reply is posted.

        Comment

        Working...