Format Datetime directive
The FORMAT-DATETIME directive was introduced in CDAP 6.4.0.
The FORMAT-DATETIME directive formats CDAP datetime values to custom pattern strings.
To convert strings to datetime values, see PARSE-AS-DATETIME.
Syntax
format-datetime :datetime_column "format"
Usage Notes
Date and time formats are specified by date and time pattern strings. Within pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes ('
) to avoid interpretation. Two single quotes ''
represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing.
The FORMAT-DATETIME directive will format CDAP datetime values to custom pattern strings. Pattern is the format for the output string.
If the column is null
, applying this directive is a no-op. The column to be formatted should be of type datetime.
Supported Patterns for Formatting and Parsing
CDAP supports the Java DateTimeFormatter patterns for formatting and parsing datetime values. For more information about the DateTimeFormatter patterns, see the DateTimeFormatter documentation.
Date and Time Pattern Examples
Prior to using these patterns, the directive PARSE-AS-DATETIME must be applied to correctly create a complete date-time string.
These examples show how date and time patterns are interpreted in the U.S. locale:
Input | Date and Time Pattern | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Troubleshooting
PARSE-AS-DATETIME is more restrictive than PARSE-AS-SIMPLEDATE. The date and time patterns for PARSE-AS-DATETIME must exactly match the input strings. For example, if you use the PARSE-AS-SIMPLEDATE directive with this input string 1/2/09 6:17, you can enter MM/dd/yy HH:mm as the format pattern and the Wrangler transforms the value to 2009-01-02T06:17Z[UTC]
. However, if you use PARSE-AS-DATETIME on the same input string, 1/2/09 6:17 and enter MM/dd/yy HH:mm as the pattern, the following error occurs:
This is because the input string doesn’t exactly match the pattern. The correct pattern in this case is M/D/yy H:mm.
To resolve this error, follow these steps:
Click Transformation steps.
Delete the parse-as-datetime step.
Add the PARSE-AS-DATETIME directive again with a pattern that exactly matches the input string.
Created in 2020 by Google Inc.