The only date in SQL

Photo by Edgar on Unsplash

The only date in SQL

Pros:

  • No varchar<->datetime conversions required

  • No need to think about the locale

  •   -- 2 day ago
      SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, DATEADD(DAY, - 2, GETDATE())))
      -- today
      SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))