i have a sqlite database on my android, whith a datetime column, that contains a date with the Format dd.MM.yyyy. It's not my Database, I'm niot able to change the Dateformat. I want to compare the date in the database with a String, which is representing a secon date, but everything I tryed failed. How can I convert this column to a valid, compareable date? date(), dattime() sdfttime() everything returns NULL.
Try this query to change the column to the proper format for a text-date (assume table named table
and column named date
):
update table set date = substr(date, 7) || "-" || substr(date,4,2)
|| "-" || substr(date, 1,2);
You can also turn this around into a where clause per this answer.
I searched on google for "sqlite3 date ddmmyyyy" and this post is the best solution (and the only one that worked for me amongst the posts listed on the bottom):
Problem:
A SQLite table contains dates in the format DD/MM/YYYY
and need to be converted to SQLite native format YYYY-MM-DD
Problem Example:
sqlite> select id, calendar_day from tbl1;
id;calendar_day
4248281;2011-06-19
4248282;2011-06-19
4248283;19/06/2011
4248284;19/06/2011
Solution Example:
sqlite> update tbl1 set calendar_day = substr(calendar_day, 7) || "-" || substr(calendar_day,4,2) || "-" || substr(calendar_day, 1,2) where id>4248282;
Result Example:
sqlite> select id, calendar_day from tbl1;
id;calendar_day
4248281;2011-06-19
4248282;2011-06-19
4248283;2011-06-19
4248284;2011-06-19
Thank you all!
Other posts inspected:
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