Examples
The following expression returns date values for the strings in the DATE_PROMISED port. TO_DATE always returns a date and time. If you pass a string that does not have a time value, the date returned always includes the time 00:00:00.000000000. If you run a session in the twentieth century, the century will be 19. In this example, the current year on the node running the
PowerCenter Integration Service
is 1998. The datetime format for the target column is MON DD YY HH24:MI SS, so the
PowerCenter Integration Service
truncates the datetime value to seconds when it writes to the target:
TO_DATE( DATE_PROMISED, 'MM/DD/YY' )
The following expression returns date and time values for the strings in the DATE_PROMISED port. If you pass a string that does not have a time value, the
PowerCenter Integration Service
returns an error. If you run a session in the twentieth century, the century will be 19. The current year on the node running the
PowerCenter Integration Service
is 1998:
TO_DATE( DATE_PROMISED, 'MON DD YYYY HH12:MI:SSAM' )
| Error. Integration Service skips this row.
|
The following expression converts strings in the SHIP_DATE_MJD_STRING port to date values:
TO_DATE (SHIP_DATE_MJD_STR, 'J')
| Dec 31 1999 00:00:00.000000000
|
| Jan 1 1900 00:00:00.000000000
|
Because the J format string does not include the time portion of a date, the return values have the time set to 00:00:00.000000000.
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( DATE_STR, 'MM/DD/RR')
| 04/01/1998 00:00:00.000000000
|
| 08/17/2005 00:00:00.000000000
|
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( DATE_STR, 'MM/DD/YY')
| 04/01/1998 00:00:00.000000000
|
| 08/17/1905 00:00:00.000000000
|
For the second row, RR returns the year 2005 and YY returns the year 1905.
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( DATE_STR, 'MM/DD/Y')
| 04/01/1998 00:00:00.000000000
|
| 08/17/1995 00:00:00.000000000
|
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( DATE_STR, 'MM/DD/YYY')
| 04/01/1998 00:00:00.000000000
|
| 08/17/1995 00:00:00.000000000
|
The following expression converts strings that includes the seconds since midnight to date values:
TO_DATE( DATE_STR, 'MM/DD/YYYY SSSSS')
If the target accepts different date formats, use TO_DATE and IS_DATE with the DECODE function to test for acceptable formats. For example:
DECODE( TRUE,
--test first format
IS_DATE( CLOSE_DATE,'MM/DD/YYYY HH24:MI:SS' ),
--if true, convert to date
TO_DATE( CLOSE_DATE,'MM/DD/YYYY HH24:MI:SS' ),
--test second format; if true, convert to date
IS_DATE( CLOSE_DATE,'MM/DD/YYYY'), TO_DATE( CLOSE_DATE,'MM/DD/YYYY' ),
--test third format; if true, convert to date
IS_DATE( CLOSE_DATE,'MON DD YYYY'), TO_DATE( CLOSE_DATE,'MON DD YYYY'),
--if none of the above
ERROR( 'NOT A VALID DATE') )
You can combine TO_CHAR and TO_DATE to convert a numeric value for a month into the text value for a month using a function such as:
TO_CHAR( TO_DATE( numeric_month, 'MM' ), 'MONTH' )