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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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_STRINGtype: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_STRINGthen 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: