Various time functions of Mysql _ MySQL

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.