In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start 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
19 - Altair
19 - Altair

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

 

binu_acs
21 - Polaris

@sakshim another option using regex_replace

REGEX_REPLACE(REGEX_REPLACE([YourField], "T", " "), "Z", "")
Spainey
9 - Comet

Here is a similar answer to @binu_acs 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