Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write current time plus 5 minutes in MySql from PHP

Tags:

php

mysql

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!

like image 448
user2840278 Avatar asked Nov 21 '13 07:11

user2840278


2 Answers

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());
like image 85
Shankar Narayana Damodaran Avatar answered Nov 06 '22 10:11

Shankar Narayana Damodaran


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

like image 5
Jason Heo Avatar answered Nov 06 '22 10:11

Jason Heo