开发者

Using less than calculation in PHP and MySQL

I have three dates to compare:

$pDate = date("d/m/Y G:i A");
$lDate = new DateTime('last wednesday G:i A');
$cDate = new DateTime('next tuesday G:i A');

If $pDate is in between $lDate and $cDate then mysql table field is updated yes

i.e. the 9th is in betw开发者_开发百科een the 8th and 14th

If $pDate is less than equal to $lDate then MySQL table field is updated no

$pDate cannot be more than $cDate

How would I write a elseif statement for the above? i.e.

elseif ( .... ) {
    mysql_query("UPDATE ... SET ... WHERE ...");
}


if ($lDate < $pDate && $cDate > $pDate) {
 // do table insert or update here
} else {
 // date is not in desired range.
}

php date compares like a number.

Heres a post you should look at. How to Compare Dates in php?


you can try IF ELSE condition in the MySQL query. try this to solve your problem, let me know if you dont.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜