Skip to content
Snippets Groups Projects
Commit b5bc4bed authored by Cam Saül's avatar Cam Saül
Browse files

Fix SQLite "last month" behavior edge case :scream_cat:

parent f23e8634
No related branches found
No related tags found
No related merge requests found
......@@ -90,7 +90,7 @@
:quarter [3 "months"]
:year [1 "years"])]
;; Make a string like DATETIME(DATE('now', 'start of month'), '-1 month')
;; The date bucketing will end up being done twice since `date` is called on the results of `date-interval` automatically. This shouldn't be a big deal because it's used for relative dates and only needs to be done once in a given query.
;; The date bucketing will end up being done twice since `date` is called on the results of `date-interval` automatically. This shouldn't be a big deal because it's used for relative dates and only needs to be done once.
;; It's important to call `date` on 'now' to apply bucketing *before* adding/subtracting dates to handle certain edge cases as discussed in issue #2275 (https://github.com/metabase/metabase/issues/2275).
;; Basically, March 30th minus one month becomes Feb 30th in SQLite, which becomes March 2nd. DATE(DATETIME('2016-03-30', '-1 month'), 'start of month') is thus March 1st.
;; The SQL we produce instead (for "last month") ends up looking something like: DATE(DATETIME(DATE('2015-03-30', 'start of month'), '-1 month'), 'start of month'). It's a little verbose, but gives us the correct answer (Feb 1st).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment