select * from user where created_date BETWEEN '2021-04-13 00:00:00' and '2021-04-13 24:00:00';
查询的时候,发现数据库实际上是有数据的,但是实际查询出来的数据是空的
select * from user t where t.created_date>= '2021-04-13 00:00:00' and t.created_date <='2021-04-13 24:00:00'; 这样查询的话,是有值的
最后查阅资料,发现数据库不识别24:00:00这样的数据
## 解决方案:
```java
1.private final static LocalDateTime LOCAL_TODAY_START = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
private final static LocalDateTime LOCAL_TODAY_END = LocalDateTime.of(LocalDate.now(),LocalTime.MAX);
使用java8的时间格式入参开始时间和结束时间,查询
2.select * from user where created_date BETWEEN '2021-04-13 00:00:00' and '2021-04-14 00:00:00'; 修改sql语句,24:00:00在数据库会默认为下一天的00点,这样就可以兼容数据查询了
小小学习了一波
需求:查询某张表中一天的数据select * from user where created_date BETWEEN '2021-04-13 00:00:00' and '2021-04-13 24:00:00'; 查询的时候,发现数据库实际上是有数据的,但是实际查询出来的数据是空的select * from user t where t.created_date>= '2021-04-13 00:00:00' and t.created_date <='2021-04-13 24:00