Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

SQL - date range from today until 3 months from now

Hello,

Sorry if this isnt the best forum to ask this, but Im digging into a SQL data warehouse, which uses a date field.  The data is populated from 2004 onwards, but I only want to pull the event data for date rows equal or later than TODAY, and less than or equal to 3 months from now.  I can hard code the dates (showm below), but I want this to be automatic and ongoing.

 

Any ideas?

 

 

Here's the hard coded exmaple...  Whats the SQL code needed to replace the hard dates with Today until 3 months from now?

 

select *
from TABLE_DETAILS
where EVENT_CODE = 'XS'
and EVENT_DATE between '01-SEP-16' and '01-DEC-16'

1 ACCEPTED SOLUTION
dedelman_clng
Community Champion
Community Champion

From a purely SQL perspective, you want to use

 

getdate()

 

to get the current date/time (convert with a mask to eliminate time if necessary)

 

and

 

dateadd(month, 3, getdate())

 

to get the date 3 months from now (use same convert mask if needed).

View solution in original post

1 REPLY 1
dedelman_clng
Community Champion
Community Champion

From a purely SQL perspective, you want to use

 

getdate()

 

to get the current date/time (convert with a mask to eliminate time if necessary)

 

and

 

dateadd(month, 3, getdate())

 

to get the date 3 months from now (use same convert mask if needed).

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.