I can convert SQLITE date format to string of any format using strtime function
i.e
select strftime('%Y-%d-%m-%Y', '2012-09-13 12:44:22');
but I have String which is in dd-MM-yyyy format, How can I convert to yyyy-MM-dd format in sqlite so that I can use that in date comparison.
Use something like this:
select datetime(substr(col, 7, 4) || '-' || substr(col, 4, 2) || '-' || substr(col, 1, 2)) from table;
where col is the column of table having the date in yyyy-MM-dd format
You can try this
String date = "23-03-2013";
try {
SimpleDateFormat format = new SimpleDateFormat(""dd-MM-yyyy");
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
date = df2.format(format.parse(str));
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With