mysql datetime 類型查詢


https://www.cnblogs.com/sea-stream/p/11299667.html

 

給的幾個例子很直觀,直接貼過來啦。docker里面用的mysql,最近可能會查得比較多。

 

 

mysql> select * from table1;
+----------+------------+-----+---------------------+
| name_new | transactor | pid | order_date |
+----------+------------+-----+---------------------+
| 1hahha | 1xiaohong | 1 | 2019-08-04 20:45:47 |
| 2hahha | 2xiaohong | 2 | 2019-08-04 20:45:57 |
| 3hahha | 3xiaohong | 3 | 2019-08-04 20:46:02 |
| 4hahha | 4xiaohong | 4 | 2019-08-04 20:46:05 |
| 3hahha | bob | 5 | 2019-08-04 20:46:08 |
| 3hahha | lee | 6 | 2019-08-04 20:46:12 |
+----------+------------+-----+---------------------+
6 rows in set (0.01 sec)

 

mysql> select * from table1 where date(order_date)='2019-08-04';
+----------+------------+-----+---------------------+
| name_new | transactor | pid | order_date |
+----------+------------+-----+---------------------+
| 1hahha | 1xiaohong | 1 | 2019-08-04 20:45:47 |
| 2hahha | 2xiaohong | 2 | 2019-08-04 20:45:57 |
| 3hahha | 3xiaohong | 3 | 2019-08-04 20:46:02 |
| 4hahha | 4xiaohong | 4 | 2019-08-04 20:46:05 |
| 3hahha | bob | 5 | 2019-08-04 20:46:08 |
| 3hahha | lee | 6 | 2019-08-04 20:46:12 |
+----------+------------+-----+---------------------+
6 rows in set (0.00 sec)

 

mysql> select * from table1 where date(order_date) between '2019-08-04' and '2019-08-04';
+----------+------------+-----+---------------------+
| name_new | transactor | pid | order_date |
+----------+------------+-----+---------------------+
| 1hahha | 1xiaohong | 1 | 2019-08-04 20:45:47 |
| 2hahha | 2xiaohong | 2 | 2019-08-04 20:45:57 |
| 3hahha | 3xiaohong | 3 | 2019-08-04 20:46:02 |
| 4hahha | 4xiaohong | 4 | 2019-08-04 20:46:05 |
| 3hahha | bob | 5 | 2019-08-04 20:46:08 |
| 3hahha | lee | 6 | 2019-08-04 20:46:12 |
+----------+------------+-----+---------------------+
6 rows in set (0.00 sec)

 

mysql> select * from table1 where order_date between '2019-08-04 20:45:47' and '2019-08-04 20:46:08';
+----------+------------+-----+---------------------+
| name_new | transactor | pid | order_date |
+----------+------------+-----+---------------------+
| 1hahha | 1xiaohong | 1 | 2019-08-04 20:45:47 |
| 2hahha | 2xiaohong | 2 | 2019-08-04 20:45:57 |
| 3hahha | 3xiaohong | 3 | 2019-08-04 20:46:02 |
| 4hahha | 4xiaohong | 4 | 2019-08-04 20:46:05 |
| 3hahha | bob | 5 | 2019-08-04 20:46:08 |
+----------+------------+-----+---------------------+
5 rows in set (0.00 sec)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM