Jump to content

checkdate function not working.. Please help


sayedsohail

Recommended Posts

Hello everyone,  my checkdate function is not working, here is my code, please help.

The  $_POST['f_date'] is 01/01/70

 

 

function checkData($date)
{
    if (!isset($date) || $date=="")
    {
        return false;
    }
    
    list($dd,$mm,$yy)=explode("/",$date);
    if ($dd!="" && $mm!="" && $yy!="")
    {
        
	return checkdate($mm,$dd,$yy);
}
    
    return false;
}


if(!$t=checkData($_POST['f_date'])){

echo "Date is wrong";}
else {
echo "date is right";}

I'm not sure exactly what is wrong with what you're using, but based on the outcome, I'd recommend you use some pattern matching to assure that your entered data is in the proper format before your check. The way you are calling the function also looks very iffy:

<?php
function checkData($date = '') {
if (!preg_match('|^(\d+)/(\d+)/(\d+)\z|', $date, $match)) {
	return FALSE;
} else {
	return checkdate($match[2], $match[1], $match[3]);
}
}

if (checkData($_POST['f_date'])) {
// Date is right
} else {
// Date is wrong
}
?>

 

Keep in mind that this is following your example and expecting the date to be in the format DD/MM/YYYY.

I tried the simpliest function, below is the code it keeps on says mysql error check manual.

 

my date field which is f_date have date displayed as 01/01/1970

and on form submit i am trying this function, i have been trying this since morning, stuck.

 

secondly when i tried to display date in human readable format from my sql statement, it just print 01/01/1970, although the date is very recent:  here is the code i used to display date in human readable format $fmdate = date('d/m/Y', "$row[model_date]");.

 

 

Here is my new code for validating date field.

 

list($y, $m, $d) = explode('/', $_POST['f_date']); 
if(checkdate($m, $d, $y)) 
{ 
   echo 'Good!'; 
} 
else 
{ 
   echo 'Bad!'; 
}  

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.