Matt
Matt

Reputation: 1103

PHP mysql adding to a timestamp

I'm working in PHP with a MySQL db and I have a current timestamp field which is created when the field is made, I then have another field which (when a page is hit) I would like a SQL statement to insert a replica of the timestamp - only 2 days ahead. Any ideas on how I would go about doing this?

Upvotes: 0

Views: 894

Answers (2)

Raffael
Raffael

Reputation: 20045

How about INSERT [...] (... , ADDTIME(NOW(),'2 00:00:00' , ...)

Upvotes: 1

Rafa
Rafa

Reputation: 1495

So you have a table like:

id
current TIMESTAMP DEFAULT CURRENT..
another TIMESTAMP

?

You can do something like

UPDATE MyTable SET another = ADDDATE(current, INTERVAL 2 DAY) WHERE id = :myId

MySQL Date and Time functions

Upvotes: 3

Related Questions