Dates

SQL Date Interview Questions

Dates come up in almost every reporting question: totals by month, the time between two events, gaps in a calendar. They are also where the most invisible errors live, because a wrong date range still returns a perfectly sensible-looking number.

What date questions ask you to do

Across the questions here, these are the shapes that come up:

  • Group totals by month, week or hour of the day
  • Work out the time between two events
  • Return the rows inside a date range
  • Find days with no activity at all
  • Find runs of consecutive days

Common mistakes with dates

If a column stores a time as well as a date, asking for everything between the 1st and the 31st loses almost all of the 31st — everything after midnight. A whole day goes missing and nothing in the result says so. Asking for dates on or after the start, and before the start of the next month, avoids it.

Questions to practice

Roles this comes up in

Companies these come from

Other topics