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?
Insert date after X days added to now() function in mysql
-
- Posts:107
Insert date after X days added to now() function in mysql
Admin
Posts:805
The date_add() function is what you're looking for:
Example
Or with PHP:
Code: Select all
DATE_ADD(date,INTERVAL expr unit)
Code: Select all
INSERT INTO users
(username, registration_date, six_days_date)
VALUES ('someone', NOW(), DATE_ADD(NOW(), INTERVAL 6 DAY));
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 )";