Page tree



Contents:

The cloud-based version of Trifacta Wrangler is now available! Read all about it, and register for your free account.

Contents:


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.
  • Inputs can be of any type. 
    • If the input is not a Datetime value and does match one of the specified formats, the output is in the following format: yyyy-MM-dd HH:mm:ss.
    • If the input is a Datetime value and does match, the output is in the input's Datetime format.

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.

  • Trifacta® Wrangler supports a wide variety of formats for Datetime fields. For more information on supported date formats, see Datetime Data Type.
  • You can explore the available Datetime formats through the Transformer page. From a column's type drop-down, select Date/Time . Then, select the formatting category. From the displayed drop-down, you can select a specific format. When this transform step is added to your recipe, you can edit it to see how the format is specified in Wrangle.
  • You can then use the DATEFORMAT function to convert the output values to your preferred Datetime format. See DATEFORMAT Function.

Basic Usage

derive type:single value: PARSEDATE(strDate, ['yyyy-MM-dd','yyyy-MM','yyyy/MM','yyyy-MM-dd') as: 'convertedDate'

Output: Generates a column of values that are structured in  yyyy-MM-dd HH:mm:ss  format if the input values in strDate match any of the four listed formats for dates.

Syntax

derive type:single value:PARSEDATE(date_col, date_formats_array)

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.

For more information on syntax standards, see Language Documentation Syntax Notes.

date_col

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

  • Inputs values can be of any type. 
  • Missing values for this function in the source data result in null values in the output.
  • Multiple columns and wildcards are not supported.

Usage Notes:


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

date_formats_array

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

  • When a non-Datetime input value matches one of the date formats in the array, the output is the input value converted to the following format:
yyyy-MM-dd HH:mm:ss
  • Datetime inputs are outputted in their source format.


Trifacta Wrangler 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.

Usage Notes:

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

Examples

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

Transform:

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:

derive type:single value:PARSEDATE(myDateStrings, ['MM/dd/yy hh:mm','MM/dd/YYYY hh:mm:ss']) as:'myParsedDates'

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:

derive type:single value:PARSEDATE(myDateStrings, ['MM/dd/yy hh:mm','MM/dd/YYYY hh:mm:ss','dd/MM/yyyy hh:mm']) as:'myParsedDates'

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.

Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 4 rates

This page has no comments.