community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Upgrade Alteryx Designer in 10 Steps

Debating whether or not to upgrade to the latest version of Alteryx Designer?

LEARN MORE

DateTimeParse in nested If statement

Asteroid

I have two date formats:

 

16 January 2018 12:10
Wednesday, January 10, 2018 12:50 PM

And proper DateTimeParse function:

DateTimeParse([Field1], "%d %B %Y") 
DateTimeParse([Field1],"%A, %B %d, %Y")

 

My formula should firstly investigate the format and apply proper re-formatting, else use default date format.

Quasar

Hi @mszpot89

 

This works

if isnull(DateTimeParse([Field1], "%d %B %Y"))
	then DateTimeParse([Field1],"%A, %B %d, %Y")
	else DateTimeParse([Field1],"%d %B %Y")
endif

Cheers

Kat

Aurora

hi @mszpot89 

 

@kat has a clever way of using isnull to check if the returned date is valid but this requires 2 date time parse operations, 1 for the if and another for the actual conversion

 

if isnull(DateTimeParse([Field1], "%d %B %Y"))
	then DateTimeParse([Field1],"%A, %B %d, %Y")
	else DateTimeParse([Field1],"%d %B %Y")
endif

 

A quicker way would be to check for the existance of a comma in your input

 

if contains([field1],",")
	then DateTimeParse([Field1],"%A, %B %d, %Y")
	else DateTimeParse([Field1],"%d %B %Y")
endif

 

A small change for 10 rows, but if you're parsing millions of rows, it can add up.

 

Dan

 

Labels