This topic is locked

Issues with Date & Time Logic

3/27/2008 6:48:53 AM
PHPRunner General questions
J
jack knowles author

Hi Forum,
Table: orders

Fields: startdate, enddate, starttime, endtime, todaydate
I've created a script within my order table, add page, before record added event.
Blah Blah

.

.

.

if (($startdate >= $todaydate)&&($startdate<=$enddate)){

// success

return true;

}elseif (($startdate=$enddate)&&($endtime < $starttime)){

return false;

}else{

echo "Error..." . "<br />";

return false;

}
All works fine with the exception of the code highlighted in blue.

Basically, if the user enters the following, then it should return an error:
startdate = 27/03/2008

starttime = 10:00

enddate = 27/03/2008

endtime = 08:00
I'm trying to error trap for basic common sense date and time enteries.
Your help would be kindly recieved.
Thanks in advance
JK

J
Jane 3/27/2008

Hi,
use == in the IF condition to compare your values:

...

elseif (($startdate==$enddate)&&($endtime < $starttime)){

return false;

}

...

J
jack knowles author 3/27/2008

Hi Jane,
Thank you for the response.
I've amended the code as follows:
if (($startdate >= $todaydate)&&($startdate<=$enddate)){

// success

return true;

$enddate)&&($endtime < $starttime)){

return false;

}else{

echo "Error..." . "<br />";

return false;

}
However when executed against the following data:

startdate = 27/03/2008

starttime = 10:00

enddate = 27/03/2008

endtime = 08:00
It simply added the data to the record, instead of producing an error.
Further Help needed.
Thanks
JK

[/color]

J
Jane 3/27/2008

Hi,
check your conditions more carefully.

For example your first condition allows to add record with the same dates and incorrect time.

if (($startdate >= $todaydate)&&($startdate<=$enddate)&& ($endtime < $starttime)){

// success

...

J
jack knowles author 3/27/2008

Hi Jane,
Still not getting the desired results. Let me provide a senerio based on todaydate = 27/03/08
Add record if following supplied:

startdate = 27/03/2008

starttime = 10:00

enddate = 27/03/2008

endtime = 10:01
Add record if following supplied:

startdate = 27/03/2008

starttime = 10:00

enddate = 28/03/2008

endtime = 10:01
Add record if following supplied:

startdate = 27/03/2008

starttime = 10:00

enddate = 28/03/2008

endtime = 08:00
Fail if following supplied:

startdate = 26/03/2008

starttime = 10:00

enddate = 27/03/2008

endtime = 10:01
Fail if following supplied:

startdate = 27/03/2008

starttime = 10:00

enddate = 26/03/2008

endtime = 10:01
Fail if following supplied:

startdate = 27/03/2008

starttime = 10:00

enddate = 27/03/2008

endtime =
Hope this clears things up a bit. From the original syntax, i cannot understand why this code is not being executed.
[color="#000080"]}elseif (($startdate=[color=#0000ff]=$enddate)&&($endtime < $starttime)){

return false;
[/color]Look forward to your response.
Thank you in advance
JK

K
kenhaley 3/27/2008

There are a couple of logic problems. First, if the startdate = enddate, you're always going to get success because of the first if. It won't get past that. After you fix that, you'll still have a problem, because there's no "return true" if the start & end dates are equal and the times are ok. Try this:
if (($startdate >= $todaydate) && ($startdate < $enddate)) {

return true;

} elseif (($startdate == $enddate) && ($starttime < $endtime)) {

return true;

} else {

return false;

}
I don't have your echo statement in there; I wasn't sure what that was for.

J
jack knowles author 3/28/2008

Kenh,
Applied code and works 100%. Thanks a million for help.
Seems i have a lot to learn yet!!!
Once again .... Thanks
JK