Convert dates with different date format into single format
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I have a field that has dates that come in different formats:
Field
06/01/2023
2023-12-23
Is there a way to convert the first example in this field into the Alteryx-supported ISO date format, while keeping the second example because it's already ISO? We can assume that it in the first example, it is always mm-dd-yyyy (June 1st, 2023).
Solved! Go to Solution.
- Labels:
- Date Time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@D_Y One way of doing this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @D_Y
There are a few options you could use and decide which suites best. Essentially it is an IF statement to apply the necessary conversion function in the formula tool.
The first is to use regex to test if the format matches the first row, in that case use the DateTimeParse function to convert the string, ELSE use the ToDate function to convert the string.
"IF REGEX_Match([String], '\d\d\/\d\d\/\d\d\d\d')
THEN DateTimeParse([String],'%m/%d/%Y')
ELSE ToDate([String]) ENDIF"
The other option is to try the ToDate function, and if that fails (returns Null), then use the DateTimeParse function to convert the string, ELSE use the ToDate function.
"IF IsNull(ToDate([String]))
THEN DateTimeParse([String],'%m/%d/%Y')
ELSE ToDate([String]) ENDIF"
Workflow is attached. Please let me know if you have any other questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@D_Y updated workflow attached
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you @ChrisWaspe @binu_acs for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@ChrisWaspe what if you have several different formats?
dd/mm/yyy
m/d/yyyy
m/dd/yyyy
mm-dd-yyyy
mm/d/yyyy
mm/dd/yy
mm/dd/yyyy
yymm-dd-yy
yymmdd
yyyy/mm/dd
yyyymmdd
