date and time from sqlite3 db

The function strftime() is used to format dates or timestamps and when you use the modifier %d the result is the day of the date in the format dd.
So why do you group by strftime('%d', saledate) (and twice)?

If you want the sum of the column KSH per day then you should group by day which you can do with the function date():

SELECT SUM(KSH) AS total FROM sales GROUP BY date(saledate)

If, as you say in your question, you want the sum of the current day, then you don’t need to group by:

SELECT SUM(KSH) AS total FROM sales WHERE date(saledate) = current_date

Note that this will work only if your timestamps in the table are in the format YYYY-MM-DD hh:mm:ss which is the only valid date format in SQLite.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top