Skip to content
Advertisement

How do I select and count records less than 1 year old?

I’m using sqflite in my Flutter application. In this example, date is the actual date(10.06.2021) and DATUM is the datafield in the DB.

I keep getting this syntax error:

E/SQLiteLog(30657): (1) near “.2021”: syntax error in “SELECT COUNT (*) FROM Shisha_table WHERE (YEAR(10.06.2021) – YEAR(DATUM)) = 1”

Advertisement

Answer

There is no YEAR() function in SQLite.

The logic of your code can be written by extracting the year of a date with the use of the function strftime():

Or, if you want the rows from the same date in last year untill today:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement