Jump to content

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!'; 
}  

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.