Page 1 of 1

help with previous dates

Posted: Thu Feb 12, 2009 9:13 pm
by greedyisg00d
Hi I am just new to programing and I am working on an scheduler for meetings. I have 2 textbox by default

textbox1 -> $date_from
textbox2->$date_to

My problem is I want to have an error checking or invalid input checker when the user clicks the submit button. For example when the user enter a previous date which must be invalid and the value of the $date_from is ahead of $date_to.

Example:
$date_from -> 02-Feb-2001
$date_to -> 14-Feb-2001 //must be invalid because its a previous date

$date_from -> 1-Mar-2009
$date_to -> 18-Feb-2009 //must be invalid because $date_from is ahead of $date_to

Any idea on how can I create error checking and display the error?

Thanks

Re: help with previous dates

Posted: Thu Feb 12, 2009 10:00 pm
by susrisha
Change the variables to time and compare.. here is a sample code

Code: Select all

 
$date_from = '04-Feb-2009';
$date_to = '08-Feb-2009';
$mydate_from = strtotime($date_from);
$mydate_to = strtotime($date_to);
if($mydate_from>$mydate_to)
{
    //the from date is earlier than the to date
        //show error or redirect from here
}
else
{
    
// the input given is correct. processing code to be got here
}
 

Re: help with previous dates

Posted: Thu Feb 12, 2009 11:03 pm
by greedyisg00d
Thanks. how about if the dates that are inputted are previous dates for example feb-14-1992 which is invalid? Since the scheduler must set dates from current to future dates only.

Re: help with previous dates

Posted: Fri Feb 13, 2009 6:17 am
by susrisha
do you mean you want to check if the given date is future date or not right??