Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

New to extract month and year

RajatRehria
8 - Asteroid

Hi Guys, is there any way-out we can extract the Month and Year from a text string?

 

e.g.

Input: FROM :|January 1, 2022 to January 31, 2022

 

Output: January 2022

 

I have similar line strings for each month.

 

Thanks.

2 REPLIES 2
DataNath
17 - Castor
17 - Castor

Hey @RajatRehria, when you say you have other lines that are similar, do you mean they're the same? If not it'd be great if you could provide a wider range of examples so we can figure out a solution that will fit. If they all follow the same format then this expression ought to do the trick:

 

DateTimeFormat(DateTimeParse([Input],'FROM :|%B %d, %Y'),'%B %Y')
cjaneczko
13 - Pulsar

Here is one method provided all of the strings start the same way and you only want the first Month/Year in the string. You can also use a Formula tool with RegExReplace.

 

RegEx Tool Replace Formula

 

(FROM :\|)(\w+)( \d+, )(\d{4})(.+)

 

 

Formula Tool Formula.

REGEX_Replace([Field1], '(FROM :\|)(\w+)( \d+, )(\d{4})(.+)', '$2 $4')

image.pngimage.png

Labels