1

I want to add some hours when alter table datetime to default current_timestamp

here the sql queries were I tried :

 ALTER TABLE [table_name] MODIFY COLUMN created_date TIMESTAMP NOT NULL DEFAULT SELECT DATE_ADD(NOW(), INTERVAL 7 HOUR);

 ALTER TABLE [table_name] MODIFY COLUMN created_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + INTERVAL 7 HOUR;

 ALTER TABLE [table_name] MODIFY COLUMN created_date TIMESTAMP NOT NULL DEFAULT NOW() + INTERVAL 7 HOUR;

but none of them work, please share me if you know how to solved this case.

mrfizh
  • 121
  • 1
  • 9

1 Answers1

2

For Trigger Try below:

DELIMITER $$

CREATE TRIGGER [trigger_name]
BEFORE INSERT
ON [table_name] FOR EACH ROW

BEGIN

SET NEW.created_date = CURRENT_TIMESTAMP + INTERVAL 7 HOUR;

END$$ 
DELIMITER ;

And then try to insert data into your table.

mrfizh
  • 121
  • 1
  • 9
Rehan Azher
  • 1,340
  • 1
  • 9
  • 17