Sei sulla pagina 1di 8

This document contains a some of the most frequently used date functions in informatica power center.

It is must have for every informatica developer.

INFORMATICA
DATE FUNTIONS IN INFORMATICA

JUKUDU

Date Functions: Date Format Strings in the Transformation Reference D, DD, DDD, DAY, DY, J Days (01-31). We can use any of these format strings to specify the entire day portion of a date. For example, if we pass 12-APR-1997 to a date function, we can use any of these format strings specify 12. HH, HH12, HH24 Hour of day (0 to 23), where zero is 12 AM (midnight). We can use any of these formats to specify the entire hour portion of a date. For example, if we pass the date 12-APR-1997 2:01:32 PM, we can use HH, HH12, or HH24 to specify the hour portion of the date. MI Minutes. MM, MON, MONTH Month portion of date (0 to 59). We can use any of these format strings to specify the entire month portion of a date. For example, if we pass 12-APR-1997 to a date function, we can use MM, MON, or MONTH to specify APR. SS , SSSS Second portion of date (0 to 59). Y, YY, YYY, YYYY , RR Year portion of date (1753 to 9999). We can use any of these format strings to specify the entire year portion of a date. For example, if we pass 12-APR-1997 to a date function, we can use Y, YY, YYY, or YYYY to specify 1997. 3.1 ADD_TO_DATE The ADD_TO_DATE function adds a specified amount to one part of a date/time value, and returns a date in the same format as the specified date. Note: If we do not specify the year as YYYY, the Informatica Server assumes the date is in the current century. It is available in the Designer and the Workflow Manager. ADD_TO_DATE( date, format, amount ) Example : The following expression adds one month to each date in the DATE_SHIPPED port. If we pass a value that creates a day that does not exist in a particular month, the Informatica Server returns the last day of the month. For example, if we add one month to Jan 31 1998, the Informatica Server returns Feb 28 1998. Also note, ADD_TO_DATE recognizes leap years and adds one month to Jan 29 2000: ADD_TO_DATE( DATE_SHIPPED, 'MM', 1 ) DATE_SHIPPED Jan 12 1998 12:00:30AM RETURN VALUE

Feb 12 1998 12:00:30AM The following expression subtracts 10 days from each date in the DATE_SHIPPED port: ADD_TO_DATE( DATE_SHIPPED, 'D', -10 ) DATE_SHIPPED Jan 1 1997 12:00:30AM RETURN VALUE Dec 22 1996 12:00AM The following expression subtracts 15 hours from each date in the DATE_SHIPPED port: ADD_TO_DATE( DATE_SHIPPED, 'HH', -15 ) DATE_SHIPPED Jan 1 1997 12:00:30AM RETURN VALUE Dec 31 1996 9:00:30AM In ADD_TO_DATE function, if the argument passed evaluates to a date that does not exist in a particular month, the Informatica Server returns the last day of the month. The following expression reveals this. ADD_TO_DATE( DATE_SHIPPED, 'MON', 3 ) DATE_SHIPPED Jan 31 1998 6:24:45PM 3.2 DATE_COMPARE RETURN VALUE Apr 30 1998 6:24:45PM The DATE_COMPARE function returns a value indicating the earlier of two dates. It is available in the Designer and the Workflow Manager. DATE_COMPARE( date1, date2 ) Example : The following expression compares each date in the DATE_PROMISED and DATE_SHIPPED ports, and returns an integer indicating which date is earlier: DA DATE_COMPARE ( DATE_PROMISED, DATE_SHIPPED ) DATE_PROMISED Jan 1 1997 Feb 1 1997 Dec 22 1997 3.3 DATE_DIFF DATE_SHIPPED

Jan 13 1997 Feb 1 1997 Dec 15 1997 RETURN VALUE -1 0 1 The DATE_DIFF function returns the length of time between two dates, measured in the specified increment (years, months, days, hours, minutes, or seconds). It is available in the Designer and the Workflow Manager. DATE_DIFF( date1, date2, format ) Example: The following expressions return the number of days between the DATE_PROMISED and the DATE_SHIPPED ports: DATE_DIFF DATE_DIFF ( DATE_PROMISED, DATE_SHIPPED, 'D' ) DATE_DIFF DATE_DIFF ( DATE_PROMISED, DATE_SHIPPED, 'DD' ) DATE_PROMISED Jan 1 1997 12:00:00AM Mar 29 1997 12:00:00PM DATE_SHIPPED Mar 29 1997 12:00:00PM Jan 1 1997 12:00:00AM RETURN VALUE -87.5 87.5 We can combine DATE functions and TEST functions so as to validate the dates. For example, while using the DATE functions like DATE_COMPARE and DATE_DIFF, the dates given as inputs can be validated using the TEST function IS_DATE and then passed to them if valid. 3.4 GET_DATE_PART The GET_DATE_PART function returns the specified part of a date as an integer value, based on the default date format of MM/DD/YYYY HH24:MI:SS. It is available in the Designer and the Workflow Manager. GET_DATE_PART( date, format ) Example: The following expressions return the day for each date in the DATE_SHIPPED port: GE GET_DATE_PART ( DATE_SHIPPED, 'D' )

GEGET_DATE_PART ( DATE_SHIPPED, 'DD' ) DATE_SHIPPED Mar 13 1997 12:00:00AM June 3 1997 11:30:44PM NULL 3.5 LAST_DAY RETURN VALUE 13 3 NULL The LAST_DAY function returns the date of the last day of the month for each date in a port. It is available in the Designer and the Workflow Manager. LAST_DAY( date ) Example : The following expression returns the last day of the month for each date in the ORDER_DATE port: LAST_DAY( ORDER_DATE ) ORDER_DATE RETURN VALUE Apr 1 1998 12:00:00AM Jan 6 1998 12:00:00AM Apr 30 1998 12:00:00AM Jan 31 1998 12:00:00AM DATE functions combine with Conversion functions also. The following expression has LAST_DAY and TO_DATE functions nested or combined together. LAST_DAY( TO_DATE( GIVEN_DATE, 'DD-MON-YY' )) 3.6 MAX The MAX function returns the latest date found in a group. It is available in the Designer. MAX( date, filter_condition ) We can return the maximum date for a port or group. Example: The following expression returns the maximum order date for flashlights: MAX( ORDERDATE, ITEM_NAME='Flashlight' ) ITEM_NAME Flashlight

Regulator System Flashlight Diving Hood Halogen Flashlight Flashlight RETURN VALUE: Oct 10 1998 3.7 MIN ORDER_DATE Apr 20 1998 May 15 1998 Sep 21 1998 Aug 18 1998 Feb 1 1998 Oct 10 1998 The MIN function returns the earliest date found in a group. It is available in the Designer. MIN( date, filter_condition ) Example: The following expression returns the oldest order date for flashlights: MIN( ORDER_DATE, ITEM_NAME='Flashlight' ) ITEM_NAME Flashlight Regulator System Flashlight Diving Hood ORDER_DATE Apr 20 1998 May 15 1998 Sep 21 1998 Aug 18 1998 Halogen Flashlight Flashlight RETURN VALUE: Feb 1 1998 3.8 ROUND

Feb 1 1998 Oct 10 1998 The ROUND function rounds one part of a date. It is available in the Designer and the Workflow Manager. ROUND( date [, format ] ) Example: The following expressions round the month portion of each date in the DATE_SHIPPED port. ROUND( DATE_SHIPPED, 'MM' ) ROUND( DATE_SHIPPED, 'MON' ) DATE_SHIPPED Jan 15 1998 2:10:30AM RETURN VALUE Jan 1 1998 12:00:00AM Similarly the ROUND function can be used to round off Year, Day or Time portions. 3.9 SET_DATE_PART The SET_DATE_PART function sets one part of a date/time value to a specified value. It is available in the Designer and the Workflow Manager. SET_DATE_PART( date, format, value ) Example: The following expressions change the month to June for the dates in the DATE_PROMISED port. The Informatica Server displays an error when we try to create a date that does not exist, such as changing March 31 to June 31: SET_DATE_PART( DATE_PROMISED, 'MM', 6 ) SET_DATE_PART( DATE_PROMISED, 'MON', 6 ) DATE_PROMISED Jan 1 1997 12:15:56AM NULL RETURN VALUE Jun 1 1997 12:15:56AM NULL Similarly the SET_DATE_PART function can be used to round off Year, Day or Time portions. 3.10 TRUNC The TRUNC function truncates dates to a specific year, month, day, hour, or minute. It is available in the Designer and the Workflow Manager. TRUNC( date [, format ] ) Example: The following expressions truncate the year portion of dates in the DATE_SHIPPED port: TRUNC( DATE_SHIPPED, 'Y' )

TRUNC( DATE_SHIPPED, 'YY' ) DATE_SHIPPED Jan 15 1998 2:10:30AM RETURN VALUE Jan 1 1998 12:00:00AM Similarly the TRUNC function can be used to truncate Month , Day or Time portions. The functions TRUNC & ROUND can be nested in order to manipulate dates.

Potrebbero piacerti anche