I want to convert sqlite query to Ormlite query.
SELECT * FROM Test where strftime('%m-%Y',Date)='11-2001'
I could not format date column like above query.
How to format Date column in Ormlite as MM-yyyy
?
Thanks.
I want to convert sqlite query to Ormlite query.
SELECT * FROM Test where strftime('%m-%Y',Date)='11-2001'
I could not format date column like above query.
How to format Date column in Ormlite as MM-yyyy
?
Thanks.
If that is the exact SQL that you want to use then you can use the
Where.raw(...)
method:However, this only seems to work if the date field is stored as a
DATE_STRING
type:The issue is that by default the Xerial JDBC driver is storing the date in the format:
Which does not [quite] match one of the approved Sqlite formats which are:
When you change it to
DataType.DATE_STRING
then it will be stored as the following which seems to work:For more info, see the Sqlite docs on date functions. Unfortunately, the documentation does not fully explain that the database values need to be in a certain format: