Looking to pull in data from your SQL Server according to a dynamic date range? We've got you covered!  

Here are some example snippets that you can add to your queries*:

*Replace any instance of  "DATE_COLUMN"  with the name of the date column / field you want to base the filter off of.

Last 30 Days

WHERE "DATE_COLUMN" >= DATEADD(DAY, -30, GETDATE())

MTD

WHERE "DATE_COLUMN" >= DATEADD(MONTH, DATEDIFF(MONTH, '20000101', CURRENT_TIMESTAMP),'20000101')

YTD

WHERE "DATE_COLUMN" >= DATEADD(YEAR,DATEDIFF(YEAR,'20010101',GETDATE()),'20010101')
AND "DATE_COLUMN" < DATEADD(YEAR,1+DATEDIFF(YEAR,'20010101',GETDATE()),'20010101')

Last Month

WHERE DATEPART(MONTH, "DATE_COLUMN") = DATEPART(MONTH, DATEADD(MONTH, -1, GETDATE()))
AND DATEPART(YEAR, "DATE_COLUMN") = DATEPART(YEAR, DATEADD(MONTH, -1, GETDATE()))

Last Year

WHERE DATEPART(YEAR, "DATE_COLUMN") = DATEPART(YEAR, DATEADD(YEAR, -1, GETDATE()))

MTD (Last Year)

WHERE "DATE_COLUMN" >= DATEADD(YEAR,-1,(DATEADD(MONTH, DATEDIFF(MONTH, '20000101', CURRENT_TIMESTAMP),'20000101')))
AND  "DATE_COLUMN" <= DATEADD(YEAR,-1,GETDATE())

YTD (Last Year): 

WHERE "DATE_COLUMN" >= DATEADD(YEAR,-1,DATEADD(YEAR,DATEDIFF(YEAR,'20010101',GETDATE()),'20010101'))
AND "DATE_COLUMN" <= DATEADD(YEAR,-1,GETDATE())

If you have questions, feel free to email us or chat in on the site!

Did this answer your question?