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.
精彩评论