jeudi 25 avril 2019

How to fix IF statement so it works to seconds

Trying to use an IF statement to open / close a payment button.

There is a variable called late which is fetching a column from a database for each specific event. The column is called latedate which is datetime type.

I have an IF statement that should show "Sorry Event Closed" if the current date and time now is after the latedate in the database but if it is before this time it will show the payment button. For some reason the statement I have done is only working when its the next hour.

For example latedate is 01/01/2019 12:01:00 and current time is 01/01/2019 12:02:00 the button is still visible until 13:00:00 then it will show "Sorry Event Closed".

I need the statement to work to the second so as above example as soon as 01/01/2019 12:01:01 is reached it will say "Sorry Event Closed".

I have tried a few different statements but the closest to working is the one below but it will not work to the second.

$late=$row["latedate"];

 if(($late) < date('Y-m-d H:i:s'))

echo "closed"

else echo "button"

So would like to see closed when the current date time is more than the datetime (latedate in the database) to the nearest second. At the moment it works but not until the next hour.

Aucun commentaire:

Enregistrer un commentaire