First day of week / Previous Week inconsistencies between Databases

I found multiple issues linked to how databases drivers interprete weeks depending on which day is chosen as a start day (example : 18301).
We 're using Postgres Read Replica for live data report and Snowflake for analytics .
It apears that if I set Monday as First Day Of Week and run a report on a Monday with Previous Week filter on postgres it returns the right data :


Executed SQL :

SELECT CAST("public"."shotguns"."created_at" AS date) AS "created_at", count(*) AS "count" FROM "public"."shotguns" WHERE ("public"."shotguns"."created_at" >= date_trunc('week', CAST((CAST(now() AS timestamp) + (INTERVAL '-1 week')) AS timestamp)) AND "public"."shotguns"."created_at" < date_trunc('week', CAST(now() AS timestamp))) GROUP BY CAST("public"."shotguns"."created_at" AS date) ORDER BY CAST("public"."shotguns"."created_at" AS date) ASC

And on Snowflake it is the week before that is returned :

SELECT date_trunc("day", CAST("PRODUCTION_DB_PUBLIC"."SHOTGUNS"."CREATED_AT" AS timestamp)) AS "CREATED_AT", count(*) AS "count" FROM "RAW"."PRODUCTION_DB_PUBLIC"."SHOTGUNS" WHERE ("PRODUCTION_DB_PUBLIC"."SHOTGUNS"."CREATED_AT" >= dateadd(day, 1, CAST(date_trunc("week", CAST(dateadd(day, -1, CAST(dateadd(week, -1, CAST(current_timestamp() AS timestamp)) AS timestamp)) AS timestamp)) AS timestamp)) AND "PRODUCTION_DB_PUBLIC"."SHOTGUNS"."CREATED_AT" < dateadd(day, 1, CAST(date_trunc("week", CAST(dateadd(day, -1, CAST(current_timestamp() AS timestamp)) AS timestamp)) AS timestamp))) GROUP BY date_trunc("day", CAST("PRODUCTION_DB_PUBLIC"."SHOTGUNS"."CREATED_AT" AS timestamp)) ORDER BY date_trunc("day", CAST("PRODUCTION_DB_PUBLIC"."SHOTGUNS"."CREATED_AT" AS timestamp)) ASC

Flamber if you're the one reading this first be indulgent, I looked for existing topics and issues/PR but couldn't find one related to Week Filters so feel free to redirect me in case there is one :pray:

Hi @gchev
Post "Diagnostic Info" from Admin > Troubleshooting.
There are known issues, some already fixed, others waiting for a fix:
https://github.com/metabase/metabase/issues/20999
https://github.com/metabase/metabase/issues/17801

@flamber
{
"browser-info": {
"language": "en-US",
"platform": "MacIntel",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"vendor": "Google Inc."
},
"system-info": {
"file.encoding": "UTF-8",
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.14.1+1",
"java.vendor": "Eclipse Adoptium",
"java.vendor.url": "https://adoptium.net/",
"java.version": "11.0.14.1",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.14.1+1",
"os.name": "Linux",
"os.version": "4.14.262-200.489.amzn2.x86_64",
"user.language": "en",
"user.timezone": "GMT"
},
"metabase-info": {
"databases": [
"postgres",
"snowflake"
],
"hosting-env": "unknown",
"application-database": "postgres",
"application-database-details": {
"database": {
"name": "PostgreSQL",
"version": "11.13"
},
"jdbc-driver": {
"name": "PostgreSQL JDBC Driver",
"version": "42.2.23"
}
},
"run-mode": "prod",
"version": {
"date": "2022-04-07",
"tag": "v1.42.4",
"branch": "release-x.42.x",
"hash": "7c3ce2d"
},
"settings": {
"report-timezone": "Etc/UTC"
}
}
}

I looked at those issue but they do not refer explicitely to datetrunc / dateadd logic linked to the Previous x week filter capability. So I think it's linked but not entirely.

@gchev If you want the correct day returned on Snowflake, then set the connection string WEEK_START=7 in Admin > Databases > (your-db) > Advanced.
And do a browser refresh.

Timezone (including DST and DoW) gets really complicated.

Timezone (including DST and DoW) gets really complicated.

I share your pain @flamber . It solved the issue :pray: