Jump to content

validate date


jenniferG

Recommended Posts

we are trying to determine ikf a date  from  a mysql database is either null

or equal to '0000-00-00';  what we tried is  below and it  does not appear to do what we need. If the date is either null or ='0000-00-00',  want a return=0, else return 1.

Thanks,

melanie

 

function check_valid_date($DATE){

/* designed to see if a date  is either null or if it is

equal to default value = '0000-00-00'

returns 0 if $date is null or =default */

    $DATE=trim($DATE);

    $CHECK1 =is_null($DATE);

    $CHECK2 = strcmp($DATE,'0000-00-00');

    if ($CHECK1 ==1 || $CHECK2 == 0){return 0;}else {return 1;}

}//check_valid_date

Link to comment
https://forums.phpfreaks.com/topic/68482-validate-date/
Share on other sites

this uses checkdate, based on how you date is formatted, change the parameters accordingly

 

checkdate(month, day, year)

 

using your date schema, YEAR-MONTH-DAY is

checkdate($date_parts[1], $date_parts[2], $date_parts[0])

 


function check_valid_date($date){

    $date = trim($date);
    $date_parts = explode("-", $date);

    if( checkdate($date_parts[1], $date_parts[2], $date_parts[0]) ){

        return 0;

    }

    return 1;
}

Link to comment
https://forums.phpfreaks.com/topic/68482-validate-date/#findComment-344264
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.