Evaluates an input against an array of Datetime format strings in their listed order. If the input matches one of the listed formats, the function outputs a Datetime value.

After you have converted your strings values to dates, If a sufficient percentage of an input strings from a column are successfully converted to one of the matching formats, the column may be retyped as Datetime.

Output: Returns a value structured in  yyyy-MM-dd HH:mm:ss  format if the input value in strDate matches any of the four listed formats for dates.


ArgumentRequired?Data TypeDescription
date_colYanyLiteral, name of a column, or a function returning values to match
date_formats_arrayYstringAn array of date format strings that are used to match against input values.

date_col

Literal, column name, or function returning values that are to be evaluated for conversion to Datetime values.


Required?Data TypeExample Value
Yesany'February 24, 2019'

date_formats_array

Array of String values of the date formats to evaluate the inputs.

yyyy-MM-dd HH:mm:ss


supports Java formatting strings, with some exceptions.

NOTE: If the platform cannot recognize the date format string, a null value is written as the output.

For more information on supported date formats, see Datetime Data Type.

Required?Data TypeExample Value
YesArray of Strings['MM/dd/yyyy','MM-dd-yyyy']

Example - formatting date values

This example illustrates several ways of wrangling heterogeneous date values, including the use of the DATEFORMAT function.

Source:

Your dataset includes the following messy date values:

MyDateStrings
2/1/00 14:20
4/5/10 11:25
6/7/99 22:00
13/7/1999 22:00
12-20-1894 15:45:00
08-12-1956 22:01:04

Transformation:

To enable easier comparison in the data grid, you choose to create a new column with the parsed values. From the above, you identify two date formats:

'MM/dd/yy hh:mm'
'MM/dd/YYYY hh:mm:ss'

You create the following transformation to parse them:

When the above step is added to the recipe, the output is as follows:

MyDateStringsmyParsedDates
2/1/00 14:202000-02-01 14:20:00
4/5/10 11:252010-04-05 11:25:00
6/7/99 22:001999-06-07 22:00:00
13/7/1999 22:0013/7/1999 22:00
12-20-1894 15:45:001894-12-20 15:45:00
08-12-1956 22:01:041956-08-12 22:01:04

The output myParsedDates column is retyped as a Datetime column with one mismatched value: 3/7/1999 22:00.

This value does not match any of our date formats specified in the array. The solution is to modify the recipe step to include the appropriate format as part of the array:

Results:

MyDateStringsmyParsedDates
2/1/00 14:202000-02-01 14:20:00
4/5/10 11:252010-04-05 11:25:00
6/7/99 22:001999-06-07 22:00:00
13/7/1999 22:001999-07-13 22:00:00
12-20-1894 15:45:001894-12-20 15:45:00
08-12-1956 22:01:041956-08-12 22:01:04

For more information on supported date formats, see Datetime Data Type.