Insert date after X days added to now() function in mysql

Discuss coding issues, and scripts related to PHP and MySQL.
Marius
Posts:107

Insert date after X days added to now() function in mysql

I have a subscription system in my website. When the users subscribe, their start date and time is added in mysql table using now() function.
I also need to insert the date and time six days from now and store it in database. How can I do it?

Admin Posts:805
The date_add() function is what you're looking for:

Code: Select all

DATE_ADD(date,INTERVAL expr unit)
Example

Code: Select all

INSERT INTO users
(username, registration_date, six_days_date)
VALUES ('someone', NOW(), DATE_ADD(NOW(), INTERVAL 6 DAY));
Or with PHP:

Code: Select all

$new_date = date('Y-m-d', strtotime("+6 days", time()));
$sql = "INSERT INTO users
(username, registration_date, six_days_date)
VALUES ('someone', NOW(), $new_date )";