Easy SELECT & filtering Free

SQL interview question: Days Between Two Dates

Calculate Account Age in Days

The retention team wants to segment users by how long they've been subscribers.

Calculate the number of days since each user's subscription_start date (as of January 1, 2026).

Return user_id, username, and days_subscribed as a whole number of days. Order by days subscribed descending.

Skills: date arithmetic with JULIANDAY

Tables

subscriptions 5 rows
  • user_id integer PK
  • username text
  • subscription_start text
user_idusernamesubscription_start
1alice_tech2024-01-15
2bob_dev2024-06-20
3carol_data2024-11-10

Keep going