Implementation method:
1. Set the field type toTIMESTAMP
2. Set the default value toCURRENT_TIMESTAMP
##Example application:
1. MySQL script implementation use case
##--Add CreateTime to set the default timeCURRENT_TIMESTAMP
ALTER TABLE `table_name` ADD COLUMN `CreateTime` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ;
CURRENT_TIMESTAMP
ALTER TABLE `table_name`MODIFY COLUMN `CreateTime` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ;
--Add UpdateTime to set the default timeCURRENT_TIMESTAMP Set the update time toON UPDATE CURRENT_TIMESTAMP
##
ALTER TABLE `table_name` ADD COLUMN `UpdateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间' ;
CURRENT_TIMESTAMP Set the update time toON UPDATE CURRENT_TIMESTAMP
ALTER TABLE `table_name` MODIFY COLUMN `UpdateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间' ;
2. MySQL tool settings
##Summary:
1. MySQL automatic management, Maintain time consistency with the database;
2. Simple and efficient, no application development support is required, MySQL automatically completes it;
The above is the detailed content of Mysql method to automatically obtain time and date. For more information, please follow other related articles on the PHP Chinese website!