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

 

 

Link to comment
Share on other sites

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

Link to comment
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.