I have a DB with multiple columns. In it a column 'Datum'.
Unfortunately I entered the wrong date format, dd.MM.yyyy.
So my data looks like this:
02.02.2017
12.12.2016
08.01.2015
etc.
I want to start with a command, e.g. delete all data from 2016 and older.
Have already tried this command:
SQL_DB.ExecNonQuery ("Delete from Rechnungen where year (Datum) <= '" 2016' ")
Unfortunately, not, year is reported as an error.
What command? And why only in Select? You do realize that dates are one of the most non-standardized data types in SQL, with each vendor treating not only the storage differently, but even how you escape them/present them in a query. It would really help if
1) You let us know what database you are talking to
2) The exact error message (not just that you get an error message)
3) You can be a little bit more specific than - does not work
Nevermind, YEAR is not supported by SQLite. It should have been
B4X:
"SELECT strftime('%Y',Datum) FROM Rechnungen LIMIT 10"
My assumption here is that you get back nothing. The date must be in a particular format for SQLite to see it as a date (see https://sqlite.org/lang_datefunc.html).
Result for
"SELECT strftime('%Y',Datum) FROM Rechnungen LIMIT 10"
is null
I also believe that this is not possible. Will change the date format now or another way via select and if query with DateTime.DateParse determine and delete the lines
Thanks for your help.
That was expected. As I said, the format is not what SQLite expects. If you can change the format, do so, otherwise, post #12 should do the trick (for deleting previous dates).
No. The column Datum does not contain a valid representation of a SQLite approved date format. It's just plain dd.dd.dddd (where d is a digit). That is why strftime does not work (once more, the actual string stored in the Datum column is not in the right format for SQLite to see it as a date). Therefore my "hack" works, since all that I do is return the last four characters of the string stored in Datum.