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

How to make your browser talk with JavaScript

Table of contents 1. The simplest example 2. Cust...

Introduction and tips for using the interactive visualization JS library gojs

Table of contents 1. Introduction to gojs 2. Gojs...

JavaScript CollectGarbage Function Example

First, let's look at an example of memory rel...

URL representation in HTML web pages

In HTML, common URLs are represented in a variety ...

MySQL 5.7.21 installation and password configuration tutorial

MySQL5.7.21 installation and password setting tut...

Calling the search engine in the page takes Baidu as an example

Today, it suddenly occurred to me that it would be...

Web Design Tutorial (4): About Materials and Expressions

<br />Previous Web Design Tutorial: Web Desi...

Let's talk about the LIMIT statement in MySQL in detail

Table of contents question Server layer and stora...

Element-ui directly clicks on the cell in the table to edit

Table of contents Achieve results Implementation ...

Detailed explanation of Docker usage under CentOS8

1. Installation of Docker under CentOS8 curl http...

SQL implementation of LeetCode (178. Score ranking)

[LeetCode] 178.Rank Scores Write a SQL query to r...