Future Date Woes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin

    #1

    Future Date Woes

    I have a simple application that handles authentication, and one of the
    things it checks is password aging. If I have something like this:

    If ("02/14/2007" <= Date.Today.ToSt ring("MM/dd/yyyy")) Then
    Messagebox.Show ("Date specified is less than current")
    Else
    Messagebox.Show ("Date specified is greater than current")
    End If


    This is causing problems with authentication, as the future date, when
    it rolls into another calander year, this expression consistently
    returns that the date specified is less than the current date, even if
    the date is 01/01/2007 and the current date is 12/31/2006. I haven't
    yet found a way around this short of iterating through each number in
    the date starting with the year.. Any suggestions?

  • RobinS

    #2
    Re: Future Date Woes

    Try converting it to a real date, or reverse the order
    of the date format so it's 2007/02/14.

    Robin S.
    -------------------------------------------
    "Kevin" <kmhuntly@gmail .comwrote in message
    news:1167615566 .317946.162900@ n51g2000cwc.goo glegroups.com.. .
    >I have a simple application that handles authentication, and one of the
    things it checks is password aging. If I have something like this:
    >
    If ("02/14/2007" <= Date.Today.ToSt ring("MM/dd/yyyy")) Then
    Messagebox.Show ("Date specified is less than current")
    Else
    Messagebox.Show ("Date specified is greater than current")
    End If
    >
    >
    This is causing problems with authentication, as the future date, when
    it rolls into another calander year, this expression consistently
    returns that the date specified is less than the current date, even if
    the date is 01/01/2007 and the current date is 12/31/2006. I haven't
    yet found a way around this short of iterating through each number in
    the date starting with the year.. Any suggestions?
    >

    Comment

    • Stephany Young

      #3
      Re: Future Date Woes

      Your prime issue is that the test you are performing is "02/14/2007" <=
      "12/31/2006".

      The first character of the string on the left is logically less than the the
      first character of the string on the right ("0" < "1") therefore the result
      is true.

      If you just deal with the values as dates then you will be fine:

      Dim _d As New DateTime(2007, 2, 14)

      If _d <= Datetime.Today Then
      ...

      I also thingk that you have a logic issue with you test. You are testing for
      <= (less than or equal to). This will give a result of true when the 2 dates
      are the same and therefore your message is inappropriate. I think your test
      should simply be for < (less than).


      "Kevin" <kmhuntly@gmail .comwrote in message
      news:1167615566 .317946.162900@ n51g2000cwc.goo glegroups.com.. .
      >I have a simple application that handles authentication, and one of the
      things it checks is password aging. If I have something like this:
      >
      If ("02/14/2007" <= Date.Today.ToSt ring("MM/dd/yyyy")) Then
      Messagebox.Show ("Date specified is less than current")
      Else
      Messagebox.Show ("Date specified is greater than current")
      End If
      >
      >
      This is causing problems with authentication, as the future date, when
      it rolls into another calander year, this expression consistently
      returns that the date specified is less than the current date, even if
      the date is 01/01/2007 and the current date is 12/31/2006. I haven't
      yet found a way around this short of iterating through each number in
      the date starting with the year.. Any suggestions?
      >

      Comment

      • Kevin

        #4
        Re: Future Date Woes

        Thanks! That worked.


        Stephany Young wrote:
        Your prime issue is that the test you are performing is "02/14/2007" <=
        "12/31/2006".
        >
        The first character of the string on the left is logically less than the the
        first character of the string on the right ("0" < "1") therefore the result
        is true.
        >
        If you just deal with the values as dates then you will be fine:
        >
        Dim _d As New DateTime(2007, 2, 14)
        >
        If _d <= Datetime.Today Then
        ...
        >
        I also thingk that you have a logic issue with you test. You are testing for
        <= (less than or equal to). This will give a result of true when the 2 dates
        are the same and therefore your message is inappropriate. I think your test
        should simply be for < (less than).
        >
        >
        "Kevin" <kmhuntly@gmail .comwrote in message
        news:1167615566 .317946.162900@ n51g2000cwc.goo glegroups.com.. .
        I have a simple application that handles authentication, and one of the
        things it checks is password aging. If I have something like this:

        If ("02/14/2007" <= Date.Today.ToSt ring("MM/dd/yyyy")) Then
        Messagebox.Show ("Date specified is less than current")
        Else
        Messagebox.Show ("Date specified is greater than current")
        End If


        This is causing problems with authentication, as the future date, when
        it rolls into another calander year, this expression consistently
        returns that the date specified is less than the current date, even if
        the date is 01/01/2007 and the current date is 12/31/2006. I haven't
        yet found a way around this short of iterating through each number in
        the date starting with the year.. Any suggestions?

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Future Date Woes

          Kevin,

          The most made error is that if people want to compare dates they still take
          the date and time.

          To compare Dates you can use on both sides DateTime.Date

          I hope this gives an idea,

          Cor


          Comment

          • Hal Rosser

            #6
            Re: Future Date Woes


            "Kevin" <kmhuntly@gmail .comwrote in message
            news:1167615566 .317946.162900@ n51g2000cwc.goo glegroups.com.. .
            >I have a simple application that handles authentication, and one of the
            things it checks is password aging. If I have something like this:
            >
            If ("02/14/2007" <= Date.Today.ToSt ring("MM/dd/yyyy")) Then
            Messagebox.Show ("Date specified is less than current")
            Else
            Messagebox.Show ("Date specified is greater than current")
            End If
            >
            >
            This is causing problems with authentication, as the future date, when
            it rolls into another calander year, this expression consistently
            returns that the date specified is less than the current date, even if
            the date is 01/01/2007 and the current date is 12/31/2006. I haven't
            yet found a way around this short of iterating through each number in
            the date starting with the year.. Any suggestions?
            Try enclosing the literal date in Pound-signs ie: if ( #02/14/2007# <= ...
            otherwise you're comparing a string to a date.
            HTH


            Comment

            Working...