Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

DateTimeFormat() and MultiFields

smile_dt06
6 - Meteoroid

I am trying to use DateTimeFormat() to convert only fields with the name contains "Date" and data type as Date to V_String with the format at dd-MM-YYYY. 

 

I use the following expression but get error. Please help

IF Contains([_CurrentFieldName_], "Date") and [_CurrentFieldType_]="Date"
THEN DateTimeFormat([_CurrentField_],"%Y-%M-%d")
ELSE [_CurrentField_]
ENDIF

 

smile_dt06_0-1623031171049.png

 

7 REPLIES 7
apathetichell
18 - Pollux

O.k. - so ignore the error for a second - two quick things:

 

In your datetimeformat you need "%m" not "%M" - capital M is minutes- not months.

 

Next I don't quite get what you are trying to do - the standard format is YYYY-MM-DD, so if you just use tostring([currentfield]) you'll get that.

 

On my machine - while it is giving the error- the workflow runs without a hitch and provides the result you want when you swap your datetimeformat as below:

 

IF Contains([_CurrentFieldName_], "Date") and [_CurrentFieldType_]="Date"
THEN DateTimeFormat([_CurrentField_],"%d-%m-%Y")
ELSE tostring([_CurrentField_])
ENDIF - that creates a string in the dd-mm-yyyy format.

 

In addition - just so you know - all selected date/time fields will end up being converted to vstring - even if "date" is not in the title. if you want to only select fields with date in the title - use a dynamic select.

 

 

apathetichell
18 - Pollux

this would allow for only converting the date fields which matched your criteria and keeping the others as vstrings...

Qiu
20 - Arcturus
20 - Arcturus

@apathetichell 
I am still geting some warning. 😂

Qiu_0-1623034401664.png

 

apathetichell
18 - Pollux

@Qiu  yeah - warning is there, but the workflow runs properly...  Here's an updated version with a more dynamic way to add back to the missing fields after the dynamic select...

atcodedog05
22 - Nova
22 - Nova

Hi @smile_dt06 

 

I was able to clear the warning by adding tostring() for current field in dateformat.

 

atcodedog05_0-1623047040377.png

 

Hope this helps 🙂

 

smile_dt06
6 - Meteoroid

Hi @apathetichell ,

 

Thank you for your help. 

 

My data will have two cases:

 

Case 1: Data type of Field named "Date......"  is DateTime (note that there will be other fields with DateTime type) then I will have to convert this field only Tostring and keep other data in other fields for further join.

 

Case 2: Data type of Field name "Date...." is already a string then I don't have to convert this field type to string. 

 

The name of this special field will vary due to typo mistake and change of system but the name will still contain "Date..." .I also think of using dynamic select but it only work for case 1, if input file falls to case 2 then the whole workflow fails, as demonstrate in the attached file.

 

As there is nearly hundred of files, I would like to build a flow that can work perfectly in both cases. Please help. Thank you.

smile_dt06
6 - Meteoroid

Thank you @apathetichell and @atcodedog05 ,

 

@atcodedog05 's workflow works perfectly. Thank you for your help. Please disregard my previous response.

Labels