Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Messy D.O.B. data

arundaka02
8 - Asteroid

Hi everyone

 

I have a list of c900 records containing date of birth data in a string format. Unfortunately the format of the data is inconsistent and I was wondering how best placed to consistently convert all values into the desired format that the DateTime tool produces? Examples of formats include, but is not exclusive to:

 

Date of birth
01/04/1995
23-05-1989
1975-12-13

 

There may be other formats but I'm unable to tell as there are a lot of records. 

 

Can anyone provide the best way to format in DateTime so the desired outcome is a date type field in yyyy-mm-dd?

 

Thanks

KA

4 REPLIES 4
BrandonB
Alteryx
Alteryx

Have you given the BB Date tool a try? https://community.alteryx.com/t5/Alteryx-Designer-Knowledge-Base/Parse-Dates-Easily-with-BB-Date/ta-...

 

This is a custom macro that accounts for a variety of different date formats. Otherwise you will need to leverage a formula tool that accounts for the different string types, looks for patterns, and calculates the actual date accordingly. 

vizAlter
12 - Quasar

Hi @arundaka02 — Try this logic:

 

It is based on your 3 sample dates, so you need to add more ELSEIF lines for other date formats (if any)

 

// for mm/dd/yyyy
IF Contains(Left([Date of birth], 3), "/") THEN 
 DateTimeFormat(DateTimeParse([Date of birth], "%m/%d/%Y"), "%Y-%m-%d") 

// for dd-mm-yyyy
ELSEIF  Contains(Left([Date of birth], 3), "-") THEN 
 DateTimeFormat(DateTimeParse([Date of birth], "%d-%m-%Y"), "%Y-%m-%d") 

ELSE 
 DateTimeFormat(DateTimeParse([Date of birth], "%Y-%m-%d"), "%Y-%m-%d") 
ENDIF

 

 

 

vizAlter_1-1601682320706.png

 

 

vizAlter
12 - Quasar

@arundaka02@BrandonB  — Thank you! 

atcodedog05
22 - Nova
22 - Nova

Hi @arundaka02 ,

 

Here is another optimized approach to it. 

 

We can directly rely on the DateTimeParse Function. If the date is not parsed by DateTimeParse  it returns a NULL() hence we can use condition on it directly.

 

See the below formula

 

IF !IsNull(DateTimeParse([Date of birth], "%m/%d/%Y")) 
THEN DateTimeParse([Date of birth], "%m/%d/%Y")

ELSEIF !IsNull(DateTimeParse([Date of birth], "%d-%m-%Y")) 
THEN DateTimeParse([Date of birth], "%d-%m-%Y")

ELSEIF !IsNull(DateTimeParse([Date of birth], "%d-%m-%Y")) 
THEN DateTimeParse([Date of birth], "%m/%d/%Y")

ELSEIF !IsNull(DateTimeParse([Date of birth], "%Y-%m-%d")) 
THEN DateTimeParse([Date of birth], "%Y-%m-%d")

// Add more date formats

ELSE Null() ENDIF

 

Output:

date.PNG

 

Currently the Date format is not in a ladder so its Null(). You can filter these off to find the new Formats that needs to be added.

 

Hope this helps 🙂

 

And hopefully there less Date Formats for you to add.

 

If this post helps you please mark it as solution. And give a like if you dont mind😀👍

Labels
Top Solution Authors