Sharanabasu Angadi Sharanabasu Angadi - 5 months ago 43
Android Question

Convert string to date in SQLITE

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.

Answer

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