Jump to content

input form date check help


PRodgers4284

Recommended Posts

I have a form that check the format of a date but i need it to check whether the date is equal to the todays current date or after. I dont what the users to be able to enter a date that has already past, can anyone help?

 

I have the following code:

 

//Date check) 

if (empty($date)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a dob
$date_message = '*Please enter a closing date*';
}

//Check the format and explode into $parts
  elseif (!ereg("^([0-9]{2})/([0-9]{2})/([0-9]{4})$", 
          $date, $parts)){
$error_stat = 1; 	

//Set the message to tell the user the date is invalid
$date_message = '*Invalid date, must be DD/MM/YYYY format*';
}
    
  elseif (!checkdate($parts[2],$parts[1],$parts[3]))
  {
  $error_stat = 1; 
  
  //Set the message to tell the date is invalid for the month entered
$date_message = '*Invalid date, month must be between 1-12*';
}

elseif (intval($parts[3]) < 2008 || 
          intval($parts[3]) > intval(date("Y")))
  {
    
    $error_stat = 1; 

   //Set the message to tell the user the date is invalid for the year entered
$date_message = '*Invalid date*';
  }

Link to comment
https://forums.phpfreaks.com/topic/92284-input-form-date-check-help/
Share on other sites

I have the following code now, but im getting an error on the line "if $date >= NOW() or if $date >= date()" not sure if i have put this is correct.

 

My code is now

 

//Date check) 

if (empty($date)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a dob
$date_message = '*Please enter a closing date*';
}

//Check the format and explode into $parts
  elseif (!ereg("^([0-9]{4})/([0-9]{2})/([0-9]{2})$", 
          $date, $parts)){
$error_stat = 1; 	

//Set the message to tell the user the date is invalid
$date_message = '*Invalid date, must be YYYY/MM/DD format*';
}
    
  elseif (!checkdate($parts[2],$parts[1],$parts[3]))
  {
  $error_stat = 1; 
  
  //Set the message to tell the date is invalid for the month entered
$date_message = '*Invalid date, month must be between 1-12*';
}

if $date >= NOW() or if $date >= date()   
  {
    
    $error_stat = 1; 

   //Set the message to tell the user the date is invalid for the year entered
$date_message = '*Invalid date*';
  }

 

 

I have the following code for the date check, but im not sure if im doin it correctly:

 

//Date check) 

if (empty($date)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a dob
$date_message = '*Please enter job closing date*';
}

//Check the format and explode into $parts
  elseif (!ereg("^([0-9]{4})/([0-9]{2})/([0-9]{2})$", 
          $date, $parts)){
$error_stat = 1; 	

//Set the message to tell the user the date is invalid
$date_message = '*Invalid closing date, must be YYYY/MM/DD format*';
}
    
  elseif (!checkdate($parts[2],$parts[1],$parts[3]))
  {
  $error_stat = 1; 
  
  //Set the message to tell the date is invalid for the month entered
$date_message = '*Invalid date, month must be between 1-12*';
}

if ($date <= NOW || $date <= date);   
  { 
     
    $error_stat = 1;  

   //Set the message to tell the user the date is invalid for the year entered 
    $date_message = '*Invalid date*'; 
  }  

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.