help with previous dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

help with previous dates

Post 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
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: help with previous dates

Post 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
}
 
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

Re: help with previous dates

Post 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.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: help with previous dates

Post by susrisha »

do you mean you want to check if the given date is future date or not right??
Post Reply