ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Find 7 months from current Date

dngnc7
8 - Asteroid

Please help!

I am pulling data from sql and it is a large amount. I only need 7 months from the current date (28 weeks) but there is not a date field only month and year. Is there a way to pull this information within the sql query in the input tool?

 

 

5 REPLIES 5
alexnajm
19 - Altair
19 - Altair

This feels like a SQL question instead of an Alteryx question?

 

If you have the data thought, you can do a Filter and use [Date field]>=DateTimeAdd(DateTimeToday(),-1,'months')

dngnc7
8 - Asteroid

I tried that but there is no date column in the file, only month and year

alexnajm
19 - Altair
19 - Altair

Then just calculate a new Date column based on your month and year! DateTimeFormat in a Formula tool or the DateTime tool should do the job: https://help.alteryx.com/current/en/designer/functions/datetime-functions.html#datetimeformat

jrlindem
12 - Quasar

To @alexnajm's point, if you do have a [Month] and [Year] field then you could just "spoof" the day by always using the 1st to create a date field:  ToString([Year]) + "-" + ToString([Month]) + "-01" and then treat that as a Data Type = Date. 

 

Once you've got that then you can apply the same DateTimeAdd function that Alex mentions above to create your logic.

 

But knowing that you have a date and year field is all you would really need.  The article that he posted is worth a review regardless as it will open up more possibilities to solve date related needs.

-Jay

abe_ibanez
10 - Fireball

Hello, 

I would use the system date within your query. If the database does not have a date field, you can extract the month and year from the system date and use that for your WHERE statements. 
For example, in Oracle, I would use EXTRACT(YEAR FROM SYSDATE) and EXTRACT(MONTH FROM SYSDATE). 

So to get your the values for your filters, you can use: 

YEAR>= EXTRACT(YEAR FROM ADD_MONTHS(SYSDATE, -7))

AND MONTH >=  EXTRACT(MONTH FROM ADD_MONTHS(SYSDATE, -7))

 

If your month is saved as the in a different format, you can also use TO_CHAR(ADD_MONTHS(SYSDATE, -7), 'format')

Labels
Top Solution Authors