Validating Date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSG001
    New Member
    • Oct 2007
    • 110

    Validating Date

    I want to take the date from user as
    MONTHYY ----MAR08,FEB08

    how do i do thisalso how i add months to the date (yyyy-mm-dd format and get a new date)



    thanks in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    For validating that, just have an array of the months ("JAN", "FEB", "MAR", etc.) and check that the first three characters (using substring()) are one of the months. Then check that the last two are digits.

    To add months, just use setMonth with the current month (getMonth()) + how many months you want to add.

    Comment

    • SSG001
      New Member
      • Oct 2007
      • 110

      #3
      Thanks i did this with pph array for motnhs to give the help to user to select in the format
      JAN08 etc
      but now i want to check two dates given in this format
      say dt1='MAR08'
      dt2='JAN10'

      I want to check if dt1> dt2 or viceversa
      and if it is greater then alert and stop the user to go to the next field

      how do i do this in javascript



      Thanks

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You need to use the Date() object. The dates need to be set in a Date object and then comparing is easy. To set the month, use an array of months and loop over until the correct month is found and that would be the number to pass to setMonth(). Use setFullYear() for the year with "20" appended. You could use setFullYear() for both - see this link.

        Comment

        Working...