简体   繁体   English

按日期获取查询 - 错误:运算符不存在:没有时区的时间戳~~未知

[英]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.

相关问题 PostgreSQL 参数错误(timestamp with time zone, timestamp without time zone) - PostgreSQL Parameter error (timestamp with time zone, timestamp without time zone) JDBC错误:运算符不存在:日期=整数 - JDBC ERROR: operator does not exist: date = integer 在将Java Date写入SQL TIMESTAMP列之前,JDBC是否将日期从JVM时区转换为数据库会话时区? - Before writing a Java Date to an SQL TIMESTAMP column, does JDBC translate the date from the JVM time zone to the database session time zone? XmlSchemaType“日期” - 没有时区? - XmlSchemaType “date” - without time zone? 日期和时区问题如何获取没有时区的日期? - issue with date and time zone how to get date without time zone? jOOQ:使用TIME ZONE解析Oracle TIMESTAMP时出错 - jOOQ: Error parsing Oracle TIMESTAMP WITH TIME ZONE 错误:列“DOJ”的类型是没有时区的时间戳,但表达式的类型是字符变化 - ERROR: column "DOJ" is of type timestamp without time zone but expression is of type character varying 尝试启动springboot应用程序时获取服务器时区值“未知”错误 - Getting server time zone value 'unknown' error while trying to start springboot application 错误:运算符不存在:boolean = bytea in spring jpa 查询和 postgres - ERROR: operator does not exist : boolean = bytea in spring jpa query and postgres 查询结果为“错误:运算符不存在:字符变化 ~~ bytea” - Query resulting into "ERROR: operator does not exist: character varying ~~ bytea"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM