Mysql database reads the statements from the front, back, back, to the back

Source: Internet
Author: User

Mysql database reads the statements from the front, back, back, to the back

Current Time:

select current_timestamp;

Output: 16:12:52

select now(); 

Output: 16:12:52

Take the first minute of the current time:

select SUBDATE(now(),interval 60 second);

Output: 16:11:52

Take the next minute of the current time:

select ADDDATE(now(),interval 60 second);

Output: 16:13:52

Change the unit above. Minutes, hours, and days can be used.

Take the time of the previous minute:

select SUBDATE(now(),interval 1 minute);

Output: 16:16:38

Take the time of the previous hour:

select SUBDATE(now(),interval 1 hour);

Output: 15:17:38

Take the time of the previous day:

select SUBDATE(now(),interval 1 day);

Output: 16:17:38
###########################

The last minute:

select ADDDATE(now(),interval 1 minute);

Output: 16:17:38

The next hour:

select ADDDATE(now(),interval 1 hour);

Output: 17:17:38

Time of the next day:

select ADDDATE(now(),interval 1 day);

Output: 16:17:38

The following is a supplement:

Mysql obtains the date of yesterday, today, tomorrow, and the time of the previous hour and the next hour.

1. Current date

select DATE_SUB(curdate(),INTERVAL 0 DAY) ;

2. Tomorrow's date

select DATE_SUB(curdate(),INTERVAL -1 DAY) ;

3. Date of yesterday

select DATE_SUB(curdate(),INTERVAL 1 DAY) ;

4. Last hour

select date_sub(now(), interval 1 hour);

5. the next hour

select date_sub(now(), interval -1 hour);

6. last 30 minutes

select date_add(now(),interval -30 minute)

7. 30 minutes later

select date_add(now(),interval 30 minute)

If you still don't want anything, read the following articles and thank you for your support.

Related Article

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.