Nikola Milojic
Nikola Milojic

Reputation: 39

DATE and TIME in MySQL (adding hour to date and selecting current date and time)

I want to do this:

INSERT INTO reservations
(user_id
,street_id
,reserved_from
,reserved_to
,reserved_date) 
VALUES 
($_SESSION['id']
, $id
, now()
, now()+1hour
, curdate()
)

Session id works, $id works, but help me for other 3 with time and date. For the backend I am using PHP. Thank you!

Upvotes: 1

Views: 43

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271231

Use the interval syntax:

VALUES ($_SESSION['id'], $id, now(), now() + interval 1 hour, curdate())

Actually, you should be passing the first two columns in as parameters, not munging the query string. So this should look like:

VALUES (?, ?, now(), now() + interval 1 hour, curdate())

Upvotes: 2

Related Questions