Start Free Trial

Alteryx Designer Desktop Discussions

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

Converting String to Date in formula

smallpotato
7 - Meteor

Hi I am new to alteryx. I have a very huge dataset with lots of Date data.

DateADateBDateCDateD...  
2023-01-312023-01-312023-01-312023-01-31   
 - -  - -  - -  - -    
2023-02-022023-02-022023-02-022023-02-02   
2023-02-022023-02-022023-02-022023-02-02   
2023-02-022023-02-022023-02-022023-02-02   
2023-02-022023-02-022023-02-022023-02-02   
2023-02-022023-02-022023-02-022023-02-02   
- - - - - - - -    
- - - - - - - -    

To avoid having conversion error " - - " not a valid date

I read all the input as string first (with input tool), and would like to remove all data with " - - " before I changed back to date as datatype

I get data like "20230131" in string with 8 as size

Since the DateTime tool only works on one column, I would like to use formula tool instead ( to avoid having 2-30 datetime tool in canvas)

I tried formula "DateTimeParse([TMP_RT_DT],'%Y%m%d')" the error of data will be truncated to "2023-01-" due to the size limit of 8.

and by using this, I only get string data that looks like date.

 

Would like to ask how can i get rid of those " - - " (with no conversion error) and get a date (date as data type) as my output.

 

9 REPLIES 9
alexnajm
18 - Pollux
18 - Pollux

I would use a Filter tool to remove those rows with the “- -“, then use a Select tool on the columns to change to a Date data type! You could also use the auto field tool in case you are expecting new columns in the future that need to be converted

 

If you want to go down the Formula route across multiple columns at one time, look at the multi field formula tool - however the first option will likely be easier. 

flying008
15 - Aurora

Hi, @smallpotato 

 

Change output type to [Date], 

 

录制_2024_02_26_11_20_35_662.gif

smallpotato
7 - Meteor

I tried something like this, and still got "ConvError: Formula (9): XXX_DT: "2069-09-14" was truncated to 8 characters" as error

smallpotato
7 - Meteor

I tried your method but got 100% null value. My source data is dbf table, so when I read it as string, I got data like 20230103, it could not be changed to date directly using select tool

smallpotato
7 - Meteor

and i still wanna avoid adding additional column, since there is really lots of data

flying008
15 - Aurora

Hi, @smallpotato 

 

As above post, maybe you can use Multi-Field Formula tool to get your want. because it can change your output type of field.

alexnajm
18 - Pollux
18 - Pollux

Ah this was not specified before - the multi field formula option works best then

smallpotato
7 - Meteor

thanks seems work for me

flying008
15 - Aurora

Hi,@smallpotato 

 

If can help you get your want, please mark it as a solution and give a like for more share.

Labels
Top Solution Authors