mysql database to retrieve the statements of seconds, minutes, hours and days before and after

mysql database to retrieve the statements of seconds, minutes, hours and days before and after

Get the current time:

select current_timestamp;

Output: 2016-06-16 16:12:52

select now();

Output: 2016-06-16 16:12:52

Get the minute before the current time:

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

Output: 2016-06-16 16:11:52

Get the next minute from the current time:

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

Output: 2016-06-16 16:13:52

By changing the units above. Can get the time before and after minutes, hours, days

Get the time of the previous minute:

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

Output: 2016-06-16 16:16:38

Get the time of the previous hour:

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

Output: 2016-06-16 15:17:38

Get the time of the previous day:

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

Output: 2016-06-15 16:17:38
###########################

Take the time after one minute:

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

Output: 2016-06-16 16:17:38

One hour after the pick-up:

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

Output: 2016-06-16 17:17:38

Time after the day of collection:

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

Output: 2016-06-17 16:17:38

The following are supplements:

mysql gets yesterday's date, today's date, tomorrow's date, 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. Yesterday's date

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. First 30 minutes

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

7. Last 30 minutes

select date_add(now(),interval 30 minute)

If you still can't find what you want, you can check out the related articles below. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • mysql gets yesterday's date, today's date, tomorrow's date, and the time of the previous hour and the next hour
  • PHP, MySQL query today, query this week, query this month's data instance (the field is a timestamp)
  • mysql get 60 days ago unix time ideas and code
  • How to write various SQL statements in MySQL to get time data for one day, one week, and one month

<<:  Solve the problem of forgetting password in MySQL 5.7 under Linux

>>:  React Hook usage examples (6 common hooks)

Recommend

Three ways to communicate between Docker containers

We all know that Docker containers are isolated f...

Use dockercompose to build springboot-mysql-nginx application

In the previous article, we used Docker to build ...

Solution to the problem of repeated triggering of functions in Vue project watch

Table of contents Problem description: Solution 1...

jQuery implements article collapse and expansion functions

This article example shares the specific code of ...

Detailed explanation of Tomcat's Server Options

1. Configuration By default, the first two are no...

iFrame is a great way to use it as a popup layer to cover the background

I have been working on a project recently - Budou ...

Vue realizes screen adaptation of large screen pages

This article shares the specific code of Vue to a...

Detailed tutorial for installing MySQL on Linux

MySQL downloads for all platforms are available a...

How to build a tomcat image based on Dockerfile

Dockerfile is a file used to build a docker image...

SQL interview question: Find the sum of time differences (ignore duplicates)

When I was interviewing for a BI position at a ce...

Alibaba Cloud Ubuntu 16.04 builds IPSec service

Introduction to IPSec IPSec (Internet Protocol Se...

harborRestart operation after modifying the configuration file

I won't say much nonsense, let's just loo...

Getting the creation time of a file under Linux and a practical tutorial

background Sometimes we need to get the creation ...