K
K
kuzyairon2020-05-11 23:48:33
PHP
kuzyairon, 2020-05-11 23:48:33

How to delete specific rows by timeframe in MYSQL DB?

The meaning is as follows.
There is a table where data is entered after the buyer makes a purchase
. Id, key, amount, dt_start, dt_end The

buyer is issued a temporary key so that he can use the service
The moment of activation and the moment the key ends.

The question is, how do I remove the key line when the key expires?

$query = "DELETE FROM n_table WHERE 'dt_start' <= NOW() AND 'dt_end' <= NOW()";
mysqli_query($db, $query);


The code is the following, I understand that it is not correct, but where is the mistake? I am only learning, I still can’t connect all the logic

UPD:

But now it deletes all lines in general

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kuzyairon, 2020-05-12
@kuzyairon

Solve with this line

$query = "DELETE FROM `number` WHERE dt_end < NOW() - INTERVAL 30 second";

Deletes by time "Now" + 30 seconds

R
Rsa97, 2020-05-11
@Rsa97

Straight quotes ( ' or " ) denote strings. Names of tables, fields, etc. are taken in back quotes ( ` ).
Well, it makes no sense to check the beginning of the interval.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question