[ACCEPTED]-Insert timestamp into a database + 7 days-sql

Accepted answer
Score: 36

There are a number of date/time functions 5 in MySQL that will do the trick here.


registration_expires=DATE_ADD(NOW(), INTERVAL 7 DAY)

You 4 can't set an expression as a default, though 3 - you'll need to do it in your INSERT queries. Notice 2 that even if your expr value is > 1 there 1 is no plural used for the unit value.

Score: 3

Or you could create a view from a query 2 where you add the interval, or when you 1 query the db always add the 7 days interval.

More Related questions