Various Mysql time functions bitsCN.com
Various time functions of Mysql
Mysql has rich time functions.
1. filtering condition in mysql Query time where the second is not 0
SQL code
SECOND (t. file_time)
2. current time
SQL code
Now ()
3. one day ago
SQL code
Select DATE_SUB (curdate (), INTERVAL 1 DAY)
4. default value of timestamp
Weird problem with mysql timestamp field
Table creation statement:
SQL code
Create table 'testtimestamp '(
'Id' int not null AUTO_INCREMENT,
'File _ time' timestamp not null,
'Scan _ time' timestamp null,
'Created 'timestamp not null,
'Modified' timestamp not null,
Primary key ('id ')
) ENGINE = InnoDB AUTO_INCREMENT = 1 default charset = utf8;
After Execution, the default value of file_time is CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP.
The default value of scan_time is NULL.
The default values of created and modified are '2017-00-00 00:00:00'
The first timestamp field of the statement to be created is CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP.
In addition, when file_time is updated, if it is not in the set group, the default value is now ()!!!???
This will lead to a default value. if this field is not found in the update statement, the current time will be filled by default.
Modify type:
SQL code
Alter table 'database'. 'tablename' change column 'columname' timestamp not null default '2017-00-00 00:00:00 ';
BitsCN.com