Skip to content
Advertisement

SQLite not selecting date

My SQlite database in my app stores the date in the format of yyyy-MM-dd HH:mm:ss. I want to query a transaction that happened on a certain month of a year but my code is not working :

SELECT COUNT(id_sale) AS total_transactions,sold_to, 
strftime('%m', sale_date) AS month, 
strftime('%Y', sale_date) AS year,
sale_date FROM sales  WHERE  month=5 AND year=2015

Advertisement

Answer

After some research I discovered that for some reason I had to do some casting for it to work.

    SELECT COUNT(id_sale) AS total_transactions,sold_to,
CAST(strftime('%m', sale_date) AS INTEGER) month, 
    CAST(strftime('%Y', sale_date) AS INTEGER) year,
    sale_date FROM sales  WHERE  month=5
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement