INTERVAL of time

From SQLZoo

Intervals of time.

schema:gisq

We can add (or subtract) a number of days (or years, months, hours, minutes or seconds) from date.

In this example we want to find the totp events that went out in the week of my 14th birthday.

SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN wk - 7 DAY
     AND wk
SELECT * FROM totp
WHERE #1976-05-20#
 BETWEEN wk - 7 
     AND wk
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN DATEADD(DAY,-7,wk)
     AND wk
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN wk - 7
     AND wk
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN DATE(wk, '-7 days')
     AND wk
SELECT * FROM totp
WHERE DATE '1976-05-20'
 BETWEEN wk - INTERVAL '7' DAY
     AND wk
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects
  • Your server today is: Laa-Laa