Hi Pritanka,

Isn't it "select s from statementTable s where extract(year from
s.statementDate) = 2020;"?

You can also do something like "select s from statementTable s where
s.statementDate >= :from and s.statementDate <= :to;" and you bind from/to
to match start/end of the year.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>


Le ven. 10 avr. 2020 à 02:59, Priyanka Sharma <sharmapriyap...@gmail.com> a
écrit :

> Hi Team,
>
> I’m working on my development using open spa dependency and have a
> question, I’m trying to extract the YEAR from the DATE datatype Column.
>
> For example: My column name is StatementDate then I’m trying
>
> Select s from statementTable where extract(year from statementDate) = 2020;
>
> But I’m getting an error as openjpa-2.2.3-snapshot;
> org.apache.openjpa.persistence.Argumentexception:
> &quot;Encountered &quot; Extract &#40; &quot; at character 87, but expected
> : ["(", ")", "*", "+", "-", ".", "/", ":", "<", "<=", "<>", "=", ">", ">=",
> "?", "ABS", "ALL", "AND", "ANY", "AS", "ASC", "AVG", "BETWEEN", "BOTH",
> "BY", "CONCAT", "COUNT", "CURRENT_DATE", "CURRENT_TIME",
> "CURRENT_TIMESTAMP", "DELETE", "DESC", "DISTINCT", "EMPTY", "ESCAPE",
> "EXISTS", "FETCH", "FROM", "GROUP", "HAVING", "IN", "INNER", "IS", "JOIN",
> "LEADING", "LEFT", "LENGTH", "LIKE", "LOCATE", "LOWER", "MAX", "MEMBER",
> "MIN", "MOD", "NEW", "NOT", "NULL", "OBJECT", "OF", "OR", "ORDER", "OUTER",
> "SELECT", "SET", "SIZE", "SOME", "SQRT", "SUBSTRING", "SUM", "TRAILING",
> "TRIM", "TYPE", "UPDATE", "UPPER", "WHERE", <DATE_LITERAL>,
> <DECIMAL_LITERAL>, <IDENTIFIER>, <INTEGER_LITERAL>, <STRING_LITERAL2>,
> <STRING_LITERAL>, <TIMESTAMP_LITERAL>, <TIME_LITERAL>].
>
> I have also tried other queries with Year(statementDate) condition.
>
> PS: I would like to get the year from the date(mm/dd/yyyy) format which is
> of Date data-type.
>
> Thanks
> Priyanka
>

Reply via email to