0

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 between 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 ...");
}

2 Answers 2

1
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?

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! so it works even if my date is in the UK format dd/mm/yyyy?
I am not sure on that, I am reading the other post as I haven't tried that before. ( my guess is yes )
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.