Write the current time plus 5 minutes in MySql from PHP

Helllo, I have a query that writes some data to a database

mysql_query ("INSERT INTO PVS (time_ended) VALUES (now())", $db_conx) or die (mysql_error()); mysql_query ("UPDATE PVS SET break = now() WHERE id = '$id'", $db_conx) or die (mysql_error()); 

I want to keep current time + 5 minutes instead of now () for time_ended and current time + 15 minutes instead of now () for break

Can someone show me a trick? Thanks!

+6
source share
2 answers

try it

 mysql_query ("INSERT INTO PVS (time_ended) VALUES ((now() + INTERVAL 5 MINUTE))", $db_conx) or die (mysql_error()); 

and

 mysql_query ("UPDATE PVS SET break = (now() + INTERVAL 5 SECOND) WHERE id = '$id'", $db_conx) or die (mysql_error()); 
+12
source

this DATE_ADD() help:

 SELECT DATE_ADD(NOW(), INTERVAL 5 SECOND); 

save current time + 5 minutes instead of now () for time_ended

 INSERT INTO PVS (time_ended) VALUES (DATE_ADD(NOW(), INTERVAL 5 MINUTE) 

current time + 15 seconds

 UPDATE PVS SET break = DATE_ADD(now(), INTERVAL 15 SECOND) WHERE id = '$id' 

and all possible INTERVAL

you can find at http://www.w3schools.com/sql/func_date_add.asp

+2
source

Source: https://habr.com/ru/post/958539/


All Articles