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

Alteryx Designer Desktop Discussions

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

need to check 2 values in Contains function

sakshim
8 - Asteroid

I have a date in a format 

2024-12-15T04:32:14Z

I want to Replace T with space and Z with no space in one go hence trying to use Contains as below:

 

if contains([creationdate],("T" or "Z")) then
replace([creationdate],"T"," ") and replace([creationdate],"Z","")

else [Creationdate]

endif

 

but it doesnt seems to be right, Can I request for help

5 REPLIES 5
alexnajm
17 - Castor
17 - Castor

You need to separate the contains statement into two:

if contains([creationdate],”T”) OR contains([creationdate],”Z”) THEN…

 

But also you can't do two replacements like that (that I am aware of)... so you need to combine those into one using ReplaceChar

if contains([creationdate],”T”) OR contains([creationdate],”Z”) THEN
ReplaceChar([creationdate],"TZ","")

else [Creationdate]

endif

 

binuacs
21 - Polaris

@sakshim another option using regex_replace

REGEX_REPLACE(REGEX_REPLACE([YourField], "T", " "), "Z", "")
mark-spain
8 - Asteroid

Here is a similar answer to @binuacs using a single Regex_Replace() function and capture groups. 

 

I have specified a pattern for the date and time format in your data, including the "T" and "Z" characters and have used the round brackets to create 2 capture groups, which I return in the replacement part of the function, specifying a space between part 1 and 2.

REGEX_Replace([Field1], "(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})Z", "$1 $2")

 

sakshim
8 - Asteroid

wonderful!!! many thanks to all of you for taking time and explaining

sakshim
8 - Asteroid

This is mainly I was looking out for

Labels
Top Solution Authors