This topic is locked

How to compare Dates & Times

3/19/2008 7:11:22 AM
PHPRunner General questions
L
Lisa2006 author

I have the following table & field setup:
Table: posting

Fields: start_date, start_time, end_date, end_time
I've placed the code snippet within the posting table | Add Page: Before record added Event
)-2);

$arr = db2time($str);

$start = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);
$str = substr($values["end_date"],1,strlen($values["end_date"])-2);

$arr = db2time($str);

$end = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);
if ($end<$start)

{

echo "Error.....";

return false;

}

else

return true;
I need to extend on this code to carry out the following:
1] if start_date < current date then error

2] if end_time < start_time then error
I'm not sure how to write. Your help & support would be much appreciated.
Lisa

Alexey admin 3/19/2008

Lisa,
use time() PHP function for this:

if ($start<time())

...


Time values can be compared as they are:

if($values["end_time"]<$values["start_time"])

L
Lisa2006 author 3/19/2008

Hi Alexey,
Thanks for the tips.
I've amended my code as below. However every combination still takes me to "error"
i.e. start < time ..... error

start = end ...... error

end < start ...... error
)-2);

$arr = db2time($str);

$start = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);
$str = substr($values["end_date"],1,strlen($values["end_date"])-2);

$arr = db2time($str);

$end = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);
if (($end<$start) || ($start<time()))

{

echo "Error:";

}
Not sure why this is happening. By the way my start_date and end_date fields are set as DATE
Please HELP!!!
Lisa

Alexey admin 3/20/2008

Lisa,
try to debug your code.

Print $end and $start values on the page to see what's wrong there