Page 1 of 1

Checking a date is in the future

Posted: Tue Jul 12, 2005 11:36 pm
by MathewByrne
I have 3 text boxes, day, month and year so I end up with somthing like

Code: Select all

/**
 * Day = 1-31
 * Month = 1-12
 * Year = 2005-whenever
 */

$day = $_POST["day"];
$month = $_POST["month"];
$year = $_POST["year"];
I want to check that the date is not only valid (via checkdate()) but also that it is in the future.

Also is there a simple way to add an integer amount of year (1, 2, 3... etc) to this date? For example if I added 1 to 1 Jan 2006 I'd get 1 Jan 2007.

Posted: Tue Jul 12, 2005 11:47 pm
by neophyte
You can use mktime() to add and subtract dates. To figure out if a date is greater than the current convert incoming string dates to unix time and compare it to time(). strtotime() is a great way to convert so is mktime().

Posted: Wed Jul 13, 2005 12:03 am
by MathewByrne
Thanks, done the trick nicely