Reputation: 719
My database has a column, for example, named
expected_event_date
data type of which is set to timestamp
and it's attribute is CURRENT_TIMESTAMP
Users input expected future event date through a form.
How shall I validate the future date in comparison with current date in this case? The server should omit an error in case users input past date.
I'm looking for something like,
$error = "invalid date"
if ($_POST['expected_event_date'] < today's date only but not time ) {
echo $error;
}
Any idea?
Upvotes: 0
Views: 1202
Reputation: 676
Here is a function for you :)
$error = "invalid date"
if ($this->isValidDate($_POST['expected_event_date'],'Y-m-d')) {
echo $error;
}
public function isValidDate($date,$dateFormat){
$date = trim($date);
$time = strtotime($date);
if(date($dateFormat, $time) < date('Y-m-d')){
return true;
}
else {
return false;
}
}
Upvotes: 1