View Full Version : Check if a date is in the past or future

07-29-2012, 12:11 AM

I have a form for reservation for courses where $data_course is the
date of the course.

I want to display error message if the date has already passed.

The problem is that it returns the error message even if the date is future.

Please let me know if there is any adust to do to the code below:

$today = getdate();

if($data_course < $today) { $errors[] = 'This course already happend';}


07-29-2012, 12:17 AM
A simple way to deal with this is record the unix time of the reservation, which is just a number and can be subtracted for comparison.

07-29-2012, 12:55 AM
I modified it as below:

$today = date("d-m-y");

I tested a future and paste date and it works ok.

Is it necessary to use strtotime function to prevent possible errors
or does it seem ok ?