Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This month and last month are the same with sqlite #2275

Closed
gseva opened this issue Mar 30, 2016 · 2 comments
Closed

This month and last month are the same with sqlite #2275

gseva opened this issue Mar 30, 2016 · 2 comments
Assignees
Labels
Milestone

Comments

@gseva
Copy link

gseva commented Mar 30, 2016

Querys filtered by last month and this month are returning the same data (and it's for this month, this is March).

I checked the logs and it's converted into WHERE (DATE(DATETIME("table"."date", 'unixepoch'), 'start of month') = DATE(DATETIME('now', '-1 months'), 'start of month')).

And DATE(DATETIME('now', '-1 months'), 'start of month')) at March 30 returns March.

This looks like this problem. The second answer seems to solve it.

  • I'm running Metabase on docker.
  • My database is sqlite
  • My Metabase version is v0.16.0.
@camsaul
Copy link
Member

camsaul commented Mar 30, 2016

Thanks for spotting this @gseva. I'll look into it.

@camsaul camsaul self-assigned this Mar 30, 2016
@camsaul camsaul added this to the 0.16.1 milestone Mar 30, 2016
@camsaul
Copy link
Member

camsaul commented Mar 30, 2016

Some more details

this month
WHERE (DATE("checkins"."date", 'start of month') = DATE(DATETIME('now'), 'start of month'))
last month
WHERE (DATE("checkins"."date", 'start of month') = DATE(DATETIME('now', '-1 months'), 'start of month'))

The problem in DATETIME('now, '-1 months') in SQLite on March 30th -> Feb 30th -> March 2nd. And the start of that month is March 1st.

The recommendation from the SO link in the description is to do

DATETIME('now', 'start of month', '-1 month')

instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants