Problems / Month-End Billing Check / Editorial
DATE_TRUNC('month', d)
+ INTERVAL 1 MONTH
- INTERVAL 1 DAY
DATE_DIFF('day', billing_date, month_end)
"Last day of month" is the textbook example of a boundary best computed by overshooting into the next period and stepping back — the calendar's irregularity (variable month lengths, leap years) is absorbed entirely by the engine's + 1 MONTH arithmetic instead of your code. Engines do offer LAST_DAY(), but it returns a DATE and quietly changes your column's type mid-pipeline; the trunc-and-interval idiom stays in timestamp-land and works letter-for-letter across DuckDB, Spark, and most warehouses.
+ 1 MONTH
LAST_DAY()
DATE
Solve Month-End Billing Check yourself →