10

Hi i have table with datetime variable. I was wondering if i can somehow change the datetime column to add 1O minutes to stored date. Perhaps some trigger has to be involved.

Thanks for help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JTC
  • 3,344
  • 3
  • 28
  • 46
  • [This](http://stackoverflow.com/questions/1436827/adding-30-minutes-to-datetime-php-mysql) might help. – ClaireG Aug 12 '13 at 13:22
  • When do you want to add this 10 minutes, when you store the row? How do you store the row? – RiggsFolly Aug 12 '13 at 13:37
  • I was wondering if i can specifi column datetime format to add 10 minutest to value when is stored no matter how – JTC Aug 12 '13 at 13:48

2 Answers2

17

I like the INTERVAL expr unit notation. It feels more readable to me:

SELECT NOW(),
       NOW() + INTERVAL 10 MINUTE;


+--------------------------------+-------------------------------+
|             NOW()              |  NOW() + INTERVAL 10 MINUTE   |
+--------------------------------+-------------------------------+
| August, 12 2013 14:12:56+0000  | August, 12 2013 14:22:56+0000 |
+--------------------------------+-------------------------------+

If you want to select existing rows and add 10 minutes to the result:

SELECT the_date + INTERVAL 10 MINUTE FROM tbl;

If you want to alter existing rows stored in a table, you could use:

UPDATE tbl SET the_date = the_date + INTERVAL 10 MINUTE;

If you want increase by force a value by 10 minutes while inserting, you need a trigger:

CREATE TRIGGER ins_future_date BEFORE INSERT ON tbl
FOR EACH ROW
  SET NEW.the_date = NEW.the_date + INTERVAL 10 MINUTE
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
2

add 10 minute in following way

       SELECT  ADDTIME(now(), '1000');
alok.kumar
  • 380
  • 3
  • 11