Member-only story
5 Ways You Misuse SQL Date Functions. And How To Be Better.
From hard coding dynamic variables to timezone mistakes, it’s time you master the subtle art of filtering SQL queries by date.
One of the first rules that was drilled into me during my first week at work was: “Whenever you query a table ALWAYS use a date filter.”
Even though this direction might seem like overkill on a smaller table not bigger than a few hundred megabytes, when you scale to terabytes or petabytes it becomes a requirement.
Since embracing that rule I’ve developed an appreciation for the power of date functions, filters and the way they can distill insights and reduce wide-scale resource consumption.
Along the way, I’ve developed my own set of best practices. I intend to share those with you to correct or prevent misguided approaches when it comes to filtering a data source by date.
1. Stop Hard Coding
Before we dive into more nuances of date filtering, I want to say up front:
Stop. Hard. Coding. Date variables.
Really this rule applies to nearly every variable you define programmatically. You should never hard code something you expect to change. That’s…