[英]Getting query by date - ERROR: operator does not exist: timestamp without time zone ~~ unknown
I am trying to get a sum of figures by today's date.我试图在今天的日期之前得到一个数字总和。 My approach is to use LocalDateTime formatted as below我的方法是使用 LocalDateTime 格式如下
yyyy-MM-dd HH:mm:ss
And The date I am picking from the server is of this format我从服务器上选择的日期是这种格式
2020-03-26 12:36:14.48947
Since the date variation keeps changing, my interest is to deal with this 2020-03-26 as both will exist from the formatted today's date and the date from the server由于日期变化不断变化,我的兴趣是处理这个2020-03-26,因为两者都存在于格式化的今天日期和来自服务器的日期
Here is the query I am using这是我正在使用的查询
"... AND p.regDate LIKE :todayDate..."
Here is the DateTimeFormertter这是 DateTimeFormertter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime today = null;
today = LocalDateTime.now();
System.out.println("here is today " + today);
With the approach above, I am getting an error.使用上述方法,我收到错误消息。 Please hw can I get todays date from the query请问我可以从查询中获取今天的日期吗
First of all, you need to a LocalDate
not LocalDateTime
to your query:首先,您需要一个LocalDate
而不是LocalDateTime
到您的查询:
LocalDate today = LocalDate.now(); // current date "2020-03-26"
// or a custom LocalDate
LocalDate today = LocalDate.of(2020, Month.MARCH, 26);
And then, to get the date part from datetime in your databse, you can use :然后,要从数据库中的日期时间获取日期部分,您可以使用:
"... AND DATE(p.regDate) = :todayDate..."
Where: DATE(p.regDate)
extract only the date part, the compare with =
not LIKE
其中: DATE(p.regDate)
仅提取日期部分,与=
not LIKE
进行比较
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.