Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.