Free Trial

Alteryx Designer Desktop Discussions

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

Parse inconsistent date formats from string

Bunbunrachel
6 - Meteoroid

Hi all, 

 

I have the following datasets:

06:00pm CDT - 03 January 2022

07:00pm CDT: 03/04/2022

09:23pm CDT - 04th Jan 2022

 

I will like to parse into date format:

03/01/2022

03/04/2022

04/01/2022

 

Appreciate any help on the above!

4 REPLIES 4
Yoshiro_Fujimori
15 - Aurora

Hi @Bunbunrachel ,

 

You can distinguish the input pattern with RegEx_Match() function.

Then you can use DateTimeParse() function for each input pattern.

I hope this works.

 

Workflow

Yoshiro_Fujimori_0-1687073072360.png

 

Formula tool expressions

Date = 

IF     REGEX_Match([Data], ".*CDT - \d{2} \w+ \d{4}")
  THEN DateTimeParse(REGEX_Replace([Data], ".*CDT - (\d{2} \w+ \d{4})", "$1"),"%d %B %Y")
ELSEIF REGEX_Match([Data], ".*CDT: \d{2}\/\d{2}\/\d{4}")
  THEN DateTimeParse(REGEX_Replace([Data], ".*CDT: (\d{2}\/\d{2}\/\d{4})", "$1"), "%d/%m/%Y")
ELSEIF REGEX_Match([Data], ".*CDT - \d{2}th \w+ \d{4}")
  THEN DateTimeParse(REGEX_Replace([Data], ".*CDT - (\d{2})th( \w+ \d{4})", "$1$2"), "%d %b %Y")
ELSE Null()
ENDIF

 

Output = DateTimeFormat([Date],"%d/%m/%Y")

 

Output

Yoshiro_Fujimori_1-1687073464596.png

 

Bunbunrachel
6 - Meteoroid

Thank you @yoshiro_fujimori

 

Bunbunrachel
6 - Meteoroid

Hi @yoshiro_fujimori, can I ask:

1. What does “.*” means?

2. Instead of including “CDT” and “-“ - is it possible to exclude since there are multiple permutations of values.

 

Thanks again for your help!

Yoshiro_Fujimori
15 - Aurora

Hi @Bunbunrachel ,

 

1. What does “.*” means?

It is a Regular Expression meaning "0 or more occurrence of any character".

As RegEx is a profound topic in itself, I recommend you watch the Interactive Lesson "Using RegEx in Expressions".

 

2. Instead of including “CDT” and “-“ - is it possible to exclude since there are multiple permutations of values.

You can relax the matching condition by calibrating the RegEx as necessary.

For example, if you want to match with any 3 uppercase alphabets, you replace "CDT" with "\u{3}" in the expression.

 

I hope this helps.

Labels
Top Solution Authors