Talend Date Routine-Function with examples- Part-2

Talend Date Routine-Function with examples- Part-2
4.57 (91.43%) 7 votes

 

Last post we have cover following functions with sample example from Talend Date Routine.

  • addDate(Date date, int nb, String dateType)
  • addDate(String string, String pattern, int nb, String dateType)
  • compareDate(Date date1, Date date2)
  • compareDate(Date date1, Date date2, String pattern)
  • getCurrentDate()
  • getDate(String pattern)
  • getFirstDayOfMonth(Date date)
  • getLastDayOfMonth(Date date)
  • getPartOfDate(String partName, Date date)
  • getRandomDate(String minDate, String maxDate)
  • isDate(String stringDate, String pattern)
  • isDate(String stringDate, String pattern, boolean ignoreTimeZone)

Now this post we will cover..

  • diffDate(Date date1, Date date2)
  • diffDate(Date date1, Date date2, String dateType)
  • diffDate(Date date1, Date date2, String dateType, boolean ignoreDST)
  • diffDateFloor(Date date1, Date date2, String dateType)
  • diffDateIgnoreDST(Date date1, Date date2)
  • diffDateIgnoreDST(Date date1, Date date2, String dateType)
  • formatDate(String pattern, java.util.Date date)
  • formatDateLocale(String pattern, java.util.Date date, String languageOrCountyCode)
  • formatDatetimeoffset(Date date)

TalendDate routine has above methods to manipulate Date. We will start with formatting date using formatDate function.

 Format Date.

  • formatDate(String pattern, java.util.Date date)

This method use to format a Date into a date/time string, it accepts two parameters and returns formatted Date/time string.

@param pattern the pattern to format.
@param date the time value to be formatted into a time string.
@return the formatted time string.

 

  • formatDateLocale(String pattern, java.util.Date date, String languageOrCountyCode)

This method Formats a Date into a date/time string using the given pattern and the default date format symbols for the given.

This method accepts three input parameters and returns formatted time string.

@param pattern the pattern to format.
@param date the time value to be formatted into a time string.
@param locale the locale whose date format symbols should be used.
@return the formatted Date/time string.

{param} string(“yyyy-MM-dd HH:mm:ss”) pattern : the pattern to format.

{param} date(myDate) date : the time value to be formatted into a time string.

{param} string(“EN”) languageOrCountyCode : the language or country whose date format symbols should be used, in lower or upper case.

 

  • formatDatetimeoffset(Date date)

This method will format date to MsSql 2008 type datetimeoffset ISO 8601 string with local time zone

Format string : yyyy-MM-dd HH:mm:ss.SSSXXX(JDK7 support it), It accepts date and return formatted Date/time string.

 Date Difference.

  • diffDate(Date date1, Date date2)

It compares two date and return result difference in number of dates, it accepts two date parameters and return difference between two dates in number of days.

@param Date1 ( first date )
@param Date1 ( second date )
@return a number of days. 

 

  • diffDate(Date date1, Date date2, String dateType)

This method will compare two dates, it accepts three parameters and returns difference in given dataType.

@param Date1 ( first date )
@param Date1 ( second date )
@param dateType value=(“yyyy”,”MM”,”dd”,”HH”,”mm”,”ss”,”SSS”) for type of return
@return a number of years, months, days … date1 – date2

Get Difference in year.

 Get Difference in Month.

 Get Difference in Days.

  • diffDate(Date date1, Date date2, String dateType, boolean ignoreDST)

This method will compare two dates, it accepts four parameters and returns the difference on the specified part.

@param Date1 ( first date )
@param Date1 ( second date )
@param dateType value=(“yyyy”,”MM”,”dd”,”HH”,”mm”,”ss”,”SSS”) for type of return
@param ignoreDST
@return a number of years, months, days … date1 – date2

examples.

Below example returns 2 not 1 in GMT+1#.

And if we pass ignoreDST=false, then it  return 1 not 2 in GMT+1#

  •  diffDateFloor(Date date1, Date date2, String dateType)

This method return difference between two dates by floor, it accepts three parameters and return the difference on the specified part.

@param Date1 ( first date )
@param Date1 ( second date )
@param dateType value=(“yyyy”,”MM”) for type of return
@return a number of years, months (date1 – date2)

 Get difference in year. 

 Get difference in Month. 

  •  diffDateIgnoreDST(Date date1, Date date2)

This method return difference between two dates ignore DST. It returns result in days.

@param Date1 ( first date )
@param Date1 ( second date )
@return a number of years, months, days … date1 – date2

  • diffDateIgnoreDST(Date date1, Date date2, String dateType)

This method compare two dates and return difference between two dates ignore DST. It accepts three parameters and returns the difference on the specified part.

@param Date1 ( first date )
@param Date1 ( second date )
@param dateType value=(“yyyy”,”MM”,”dd”,”HH”,”mm”,”ss”,”SSS”) for type of return
@return a number of years, months, days … date1 – date2

This way we have seen all the function, and their use case, you can use these functions in any expression builder or code component like tJava, tJavaRow, tJavaFlex.

I use tJava to demonstrate all these functions. Next post i will show how to use these functions in various components.

About dwetl

Leave a Reply

Your email address will not be published. Required fields are marked *