What are the time functions of Mysql
Editor to share with you what the time functions of Mysql, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Mysql has plenty of time functions.
Filter conditions with seconds not equal to 0 in 1.mysql query time
Sql code
SECOND (t.file_time)
two。 Current time
Sql code
Now ()
3. A day ago,
Sql code
Select DATE_SUB (curdate (), INTERVAL 1 DAY)
4.timestamp default value
The weird problem of mysql timestamp field
Create a table 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 for created and modified are '0000-00-0000: 00: 00'
It's a strange question that the first timestamp field of the creation statement is CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
And when file_time is in update, if it is not in the set group, it will default to now ()!
This results in a default value, and if this field is not present in the update statement, the current time is populated by default.
Type of modification:
Sql code
ALTER TABLE `database`.`tablename` CHANGE COLUMN `columname`columname` TIMESTAMP NOT NULL DEFAULT '0000-00-0000: 0000'
These are all the contents of the article "what are the time functions of Mysql". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!