Puspender Tanwar wrote:The @CreationTimestamp stores the date in format like : "2020-11-20 17:36:46", but the LocalDatTime.now() gives "2020-11-20T17:36:46"
That's not correct, you're mixing the values for storing and displaying. A database may store its dates, times and timestamps (including LocalDateTime) in one format, and display it differently. The same goes for LocalDateTime.now(). In the end, for JPA and JPQL, they're both still LocalDateTime, and for the database whatever type the column has.
For JSON it's the same. In JSON it's actually nothing but a string, but as soon as you change it back into an object it's a LocalDateTime again.
So in short: just compare the dates using
>,
<=, etc, and let JPA and the database take care of any conversion:
Disclaimer: thiscode has not been tested, or even compiled. It's the idea that counts.