date validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swapnali143
    New Member
    • Mar 2012
    • 34

    date validation

    hey friends can you give some example to validate date accepted by user in variable
    as follows
    int day;
    int month;
    int year;
    It must validate entered details are correct or not ans
    It must check that date is more than System date or not
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Just write a date validation function. It would take 3 arguments and return true or false of the 3 arguments are a valid date or not.

    Then write a date comparison function that takes 6 arguments and returns 0 if the two dates are equal, <0 of the first date is less than the secnd date and >0 of the first date is greater than the secnd date.

    This is the same setup used by strcmp so everyone is used to seeing it.

    I can help with your code but I can't provide it.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      "give some example to validate date accepted by user"... do you mean accepted or provided?
      Take day... what integers would be valid for month of Jan?
      Ans:>0 and <32. Write the algorithm then some code and show where your problems lie. Post it on this forum for help

      Comment

      • swapnali143
        New Member
        • Mar 2012
        • 34

        #4
        Can you provide me code for date validation function and date comparison function??

        Comment

        • swapnali143
          New Member
          • Mar 2012
          • 34

          #5
          Ex..
          For Date Of Birth
          Day : 29
          Date : 2
          Year :2014

          Its invalid date..

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            We don't "provide" code, we will help if you have a problem with the code you have written. Consider these questions

            1. What is the valid range of the year?
            2. What is the valid range of the month?
            3. What is the valid range of the day? Is it dependent on any other fields?

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              Also consider whether your application needs to work with a subset of valid dates. For example, a date-of-birth field might reject valid future dates and valid dates more than 120 years in the past.

              Comment

              Working...