How to convert the date pattern of a string value

When you want to change the date pattern of your received string and you don’t want to use a date format as an output then use the statement below in your tMap component.

TalendDate.formatDate(“yyyy-MM-dd”,
TalendDate.parseDate(“yyyy-MM-dd’T’HH:mm:ss.SSS”, row1.Date)
)

Example:

1. Drag the tFixedFlowInput component to your grid

  • Add the schema

Date pattern string schema

  • Add the value “2017-09-17T13:42:45.456” to the tFixedFlowInput component

Date pattern string tFixedFlowInput

2. Add the tMap to your grid

  • Connect the tMap to you tFixedFlowInput component (Main)
  • Add the output table out1
  • Add column newDate
  • Add the code above to the expressen of the newDate output column
  • Connect the row1.Date to the out1.newDate

The TalendDate.parseDate converts your input date string to a date format. Function TalendDate.formatDate converts it back to a string format.

Date pattern string tMap

3. Connect the tLogRow component to the tMap component

  • Run your job and see the execution log

Date pattern string Job

Date pattern string job Execution log

You can find my other conversion examples here

One Comment

Leave a Reply