Date Validation, Kinda'

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Date Validation, Kinda'

    Howdy,

    Has anyone written any date validation function or sequence. I have
    looked around, but haven't found anything. I am cobbling togather
    something, but was hoping to not have to re-invent the wheel. The date
    is formatted YYYYMMDD and is input by the user;

    $userCentury = substr($userDate, 0, 2); //must be 20 (no problem)
    $userYear = substr($userDate, 2, 2); //must be 03 or better
    $userMonth = substr($userDate, 4, 2); // 01-12
    $userDay = substr($userDate, 6, 2); // 01-31

    It doesn't matter if the month is 02 and they have entered 31 as the
    day. If any one of the four conditions is not true it gives them a
    warning. Anyone done this before?

    Thanks!

    Jay

    Jay Blanchard Guest

  2. Similar Questions and Discussions

    1. [PHP] Date Validation, Kinda'
      Now that I'm thinking about it, what is your goal with this? Is it to make sure the date entered is within a certain range when compared to another...
    2. combo box date validation
      Hi, As per our requirement, we need to put combo boxess for date input. we are giving the user to input as dd month year format from the given...
    3. Date Validation
      I'm trying to find some Coldfusion code that will allow me to validate a date to make sure that it's in MM/DD/YY format and is actually a valid...
    4. Date Range Validation
      Hello; CL_FRST (08/10/2004) and CL_LST (05/24/2005) holds the beginning and ending date of school calendar which is also prepopulated for every...
    5. date validation?
      How to write an IsDate function that actually checks for a particular date format? Using try-catch on Convert.ToDateTime(sDate) doesn't catch...
  3. #2

    Default Re: [PHP] Date Validation, Kinda'

    I wrote a little function to check if a date is valid. All the hard
    stuff is done by the checkdate() function, but function just returns a
    date if valid or false if not:
    function validDate($year,$month,$day) {
    if(checkdate($month,$day,$year)) {
    return date("Y-m-d", mktime(0,0,0,$month,$day,$year));
    } else {
    return false;
    }
    }

    You could easily add some checking to see if it's within a range if
    it's a valid date.


    On Thursday, August 21, 2003, at 03:29 PM, Jay Blanchard wrote:
    > Howdy,
    >
    > Has anyone written any date validation function or sequence. I have
    > looked around, but haven't found anything. I am cobbling togather
    > something, but was hoping to not have to re-invent the wheel. The date
    > is formatted YYYYMMDD and is input by the user;
    >
    > $userCentury = substr($userDate, 0, 2); //must be 20 (no problem)
    > $userYear = substr($userDate, 2, 2); //must be 03 or better
    > $userMonth = substr($userDate, 4, 2); // 01-12
    > $userDay = substr($userDate, 6, 2); // 01-31
    >
    > It doesn't matter if the month is 02 and they have entered 31 as the
    > day. If any one of the four conditions is not true it gives them a
    > warning. Anyone done this before?
    >
    > Thanks!
    >
    > Jay
    >
    >
    > --
    > PHP General Mailing List ([url]http://www.php.net/[/url])
    > To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >
    >
    --
    Brent Baisley
    Systems Architect
    Landover Associates, Inc.
    Search & Advisory Services for Advanced Technology Environments
    p: 212.759.6400/800.759.0577

    Brent Baisley Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139