Mysql date and time format adds 10 minutes

Hi, I have a table with a datetime variable. I was wondering if I can somehow change the datetime column to add 1 minute for the saved date. Perhaps some kind of trigger is involved.

thanks for the help

+4
source share
2 answers

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

 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 modify existing rows stored in a table, you can use:

 UPDATE tbl SET the_date = the_date + INTERVAL 10 MINUTE; 

If you want to increase strength by 10 minutes on insertion, you will 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 
+7
source

add 10 minutes as follows

  SELECT ADDTIME(now(), '1000'); 
+1
source

Source: https://habr.com/ru/post/1496589/


All Articles