user2840278
user2840278

Reputation: 281

Write current time plus 5 minutes in MySql from PHP

Helllo, I have a query that writes some data to the 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());

What I want is to store current time + 5 minutes instead of now() for time_ended, and current time + 15 seconds instead of now() for break

Can someone show me the trick? Thank you!

Upvotes: 13

Views: 34147

Answers (2)

Jason Heo
Jason Heo

Reputation: 10236

this DATE_ADD() help:

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

store 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 sec

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

Upvotes: 5

Try like this

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());

Upvotes: 30

Related Questions