Date Checking

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javaEddie
    New Member
    • Nov 2008
    • 2

    Date Checking

    I need to ensure that a date entered is within the next calendar year. If it is more than one year ahead it has to be rejected - can anyone help with how to achieve this?

    Thanks alot
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Have a look at GregorianCalend ar, try some code and post again here if you still have problems.

    Comment

    • javaEddie
      New Member
      • Nov 2008
      • 2

      #3
      Success!

      After a few attempts at different potential solutions, the below appears to have worked, didn't even need to use a calendar in the end :

      Date oneYearAhead = new Date();
      oneYearAhead.se tYear(oneYearAh ead.getYear() + 1);

      Should be noted that the setYear method here is actually deprecated .........

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by javaEddie
        Success!
        ...

        Should be noted that the setYear method here is actually deprecated .........
        ... whereas the GregorianCalend ar.roll method is not deprecated.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by javaEddie
          Should be noted that the setYear method here is actually deprecated .........
          ... so maybe at Java's next update your 'solution' might not work anymore.

          kind regards,

          Jos

          Comment

          Working...