I want to do something which is not complicated but I do not manage to succeed even after I tried a lot of things….
First of all, I have a database mysql with a row of timestamp type. I insert into it elements with a date like this:
$date = date('Y-m-d H:i:s', time());
$req =mysql_query("INSERT INTO my_table (id, departement, voie, date,message)
VALUES ('', '$departement_token', '$voie_token','$date' , '$message_token')");
The result of this code line is a date element like this : 2012-07-19 20:18:17
I want to delete all elements with a date > current date + 20 minutes and I do not succeed…
I tried this:
mysql_query("DELETE FROM my_table WHERE DATE_SUB(date,INTERVAL 20 MINUTE) ORDER BY date");
And this:
$req=mysql_query("DELETE FROM my_table WHERE date >= TIMESTAMPADD(MINUTE,-20,NOW())
ORDER BY date");
And this:
$timePlus20min = time() + 1200;
//et on compare les deux dates
$req = mysql_query(
"DELETE FROM my_table WHERE UNIX_TIMESTAMP(date) >= '$timePlus20min' ORDER BY date");
But none of this works. Could you help me please, I think it’s not too difficult but I’m out of ideas…
try this :
Bonne chance à toi / Good luck