0

How can I add certain amount of time from now in mysql?

INSERT INTO rank(id, username, rank_type, time_start, time_end, activated) 
VALUES (NULL, 'somename', 1, NOW(), DATE(NOW() + INTERVAL 30 DAY), 0);

It says syntax error. I think the problem is caused by DATE function. Also tried to use NOW() + INTERVAL 30 DAY, but it didn't work either.

Ike Walker
  • 64,401
  • 14
  • 110
  • 109
user2564336
  • 35
  • 1
  • 5
  • possible duplicate of [Mysql datetime format add 10 minutes](http://stackoverflow.com/questions/18188056/mysql-datetime-format-add-10-minutes) – Sylvain Leroux Aug 14 '13 at 21:21

2 Answers2

1

I think DATE_ADD(date,INTERVAL expr type) is what you are looking for..

INSERT INTO rank(id, username, rank_type, time_start, time_end, activated) 
VALUES (NULL, 'somename', 1, NOW(), DATE_ADD(NOW(), INTERVAL 30 DAY),0);

Some documentation can be found here

Here is an SQLFiddle

Joel
  • 4,732
  • 9
  • 39
  • 54
0

The problem isn't in the date math. Just leave off the second parameter to DATE(), as in:

INSERT INTO rank(id, username, rank_type, time_start, time_end, activated) 
VALUES (NULL, 'somename', 1, NOW(), DATE(NOW() + INTERVAL 30 DAY));

Here's an SqlFiddle: http://sqlfiddle.com/#!2/f479f/1

Curt
  • 5,518
  • 1
  • 21
  • 35