Issue
I have an existing JPA @Query that I need to add an addition condition to the WHERE such that it'll only return rows where the current date matches that of a timestamp column. Basically wondering if something along the lines of this is possible:
@Query("SELECT .. " +
"WHERE .. " +
"AND isCurrentDay(c.completedTs))"
Otherwise can accomplish what I need with a native query.
Edit: My solution ended up being to use a Native Query like:
@Query(value = "SELECT ... " +
"WHERE ... " +
"AND CONVERT (date, c.completedTs) = CONVERT (date, GETDATE()))",
nativeQuery = true)
Solution
I'll be it would be safer to do it through native queries using the CURDATE
sql statement of the language you are writing in. For example, for MySQL + JPA it would look something like this:
@Query("SELECT .. " +
"WHERE .. " +
"AND WHERE DATE(`completed_ts`)=CURDATE()",
nativeQuery = true)
Answered By - Begging
Answer Checked By - David Marino (JavaFixing Volunteer)