Erik Darling has started a new series on how hard it can be to get a date:
I’ll often see people need to “flatten” dates to certain intervals.
By flatten, I mean the start of a day, week, month, or year, and likewise for the end values to all those intervals.
I’ve seen some really bad implementations of this. Most notable was probably a scalar valued function that converted a datetime to a 10 character string to remove the time portion.
In every where clause.
Click through for additional introductory notes and some links to good resources.