Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to query date range by mysql

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to query the date range of mysql, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In mysql, you can use the "BETWEEN AND" keyword to query the specified date range, which is used to determine whether the value of the field is within the specified range. The syntax is "SELECT * FROM table name WHERE field name between 'time 1' and 'time 2'".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to query date range by mysql

MySQL provides the BETWEEN AND keyword to determine whether the value of the field is within the specified range.

BETWEEN AND requires two parameters, the start and end values of the range. If the field value is within the specified range, these records are returned. If it is not within the specified range, it will not be returned.

The basic syntax format for using BETWEEN AND is as follows:

[NOT] BETWEEN value 1 AND value 2

Where:

NOT: an optional parameter that represents a value outside the specified range. If the field value does not meet the value within the specified range, these records are returned.

Value 1: represents the starting value of the range.

Value 2: represents the end value of the range.

The BETWEEN AND and NOT BETWEEN AND keywords are useful when querying records within a specified range. For example, inquire about the age of the student, date of birth, salary level of the employee, and so on.

Examples are as follows:

The following table, query, create_time is datetime type, query data in two date ranges.

Method 1. Between...and (recommended)

SELECT * FROM k_student WHERE create_time between '2019-07-25 0000 and 33' and '2019-07-25 0000VOUR 54MAV 33'

Method 2. Size is smaller than the number.

SELECT * FROM k_student WHERE create_time > = '2019-07-25 0000 AND create_time 0033'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report