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
Solved! Go to Solution.
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
@sakshim another option using regex_replace
REGEX_REPLACE(REGEX_REPLACE([YourField], "T", " "), "Z", "")
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")
wonderful!!! many thanks to all of you for taking time and explaining
This is mainly I was looking out for