简体   繁体   中英

MySQL - Create table with a specific TIMESTAMP format

Is there any way to create a table with a specific TIMESTAMP format (HH:mm:00) where I need to fix sec to 00.

CREATE TABLE `published` (
  `time_pub` timestamp() NULL DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

You can't change the way the timestamp is stored. Only the way it is presented in your select statements.

Another solution would be to store the data in a hour and minute column having an integer data type.

尽管在创建表时无法指定时间格式,但是当将数据插入数据库时​​,可以使用MySQL date_format函数将第二部分固定为00。

insert into TABLE_NAME values (date_format(now(), '%H:%m:00'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM