How to Convert varchar date type value to date format in JPQL order by

Hi,

My column is varchar and similarly my entity is string, i want to sort desc by using that column since it is varchar values are not getting sorted as per date desc.

Any solution to sort varchar column as per date.

Dl.setSort(Sort.by(Sort.Direction.DESC,“createdOn”));

Hello,

The first solution coming to mind is to use jpql query and function which allows to call sql functions.
See this answer for example: Is it possible to apply Group by clause on the result of this function - #3 by subbotin - CUBA.Platform
Suitable sql function depends on database platform used, e.g. for postgresql it will be to_date.

Regards,
Dmitry

1 Like