Hi Alteryx community
Requesting how to get a date from a string and convert it into a date? Examples:
Input:
Interim Report 04-17-24B
Interim Report 04-02-24
Output-date type:
04-17-2024
04-02-2024
Thank you
Solved! Go to Solution.
DateTimeParse(Regex_Replace([Input], ".+\s(\d\d-\d\d-\d\d).*", "$1"), "%m-%d-%y")
Note that your output date type is not a date in Alteryx - dates follow the ISO format yyyy-mm-dd. If you want it to be in the format you have above, you need to use a DateTimeformat to convert it back to a string in the format you want.
Use two separate formulas:
1) output data type String, create new field F1: REGEX_Replace([Original text], ".*(\d{2}\-\d{2}\-\d{2}).*", "$1")
2) output data type Date: DateTimeParse([F1],"%m-%d-%y")
or combine the formulas into one.
Chris
@PassION_es
formula to get your expected output
DateTimeFormat((DateTimeParse(Regex_Replace([Input], ".+\s(\d\d-\d\d-\d\d).*", "$1"), "%m-%d-%y")),"%m-%d-%Y")
hope this help.