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

Mysql time comparison

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces mysql time for comparison, the content of the article is carefully selected and edited by the author, with a certain pertinence, for everyone's reference significance is still relatively great, the following with the author to understand the mysql time to compare it.

Read the Mysql document on date field comparison. When making a date comparison, mysql automatically converts the date into a number for comparison. After the where condition, when using the string format date to compare with the DATE,DATETIME,TIMESTAMP,TIME type field, the string format is not strict, you can use any format delimiter to represent the date, such as "2018-09-11", "2018-09-11", "2018-09-11" for mysql, it is the same date. If there is no delimiter, such as "20180911", it is the same as "2018-09-11" or other delimited dates. For example, the following figure

Select a from t1 where a

< '2018#09#11';与select a from t1 where a < '2018-09-11';与select a from t1 where a < '20180911';所代表的意义是相同的,都是查询日期小于2018年9月11日的数据也就是说上图的查询语句,完全可以重写为,这么做的好处?就是会使用索引,是查询更快select a from t1 where a < '2018-09-11'; 当将日期类型字段与字符串型日期进行,>

=, = '2018-09-12 select testdate FROM T1 WHERE testdate > = 20180912 select MOD (testdate,100) FROM T1 WHERE testdate > = 20180912 select testdate FROM T1 WHERE testdate > =' 20180912'

Mysql allows you to store "0000-00" as the "0" value of the DATE type, also known as a virtual date. It is more convenient than storing null values in some scenarios. If you save an illegal date value to a DATE type field, mysql is stored as "0000-00-00" by default. If the "0" value is not allowed to be stored, enable the NO_ZERO_DATE parameter.

You can also use the unix_timestamp function to convert the character time into a unix timestamp.

Select meeting_id,meeting_name,start_time,end_time from meeting_data where meeting_id REGEXP'[0-9] {4} 0001' and unix_timestamp (start_time)

< unix_timestamp(NOW()) and unix_timestamp(end_time) >

Unix_timestamp (NOW ())

After reading the above about mysql time comparison, many readers must have some understanding, if you need to get more industry knowledge and information, you can continue to follow our industry information column.

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