Convert String To Date

Convert String To Date
4.17 (83.33%) 6 votes

This Post I will describe you, how to Convert String to date in Talend. I will use various string dates to demonstrate.

  • Converting simple string with consistent format: “MM/dd/yyyy hh:mm”

12/21/2000 0:00

we will convert above date with “MM/dd/yyyy hh:mm” format. for that we will use below built in function from TalendDate routine.

above function will return Date object if you print it will give you output as

Thu Dec 21 00:00:00 IST 2000

if you want this date in any other format then use below function.

TalendDate.formatDate(pattern, Dated) will return date in string type “21-Dec-2000″ .

we can parse below non consistent formatted string using same method.

12/21/2000 0:00
5/11/2007 0:00
5/1/2009 0:00

  • convert heterogeneous formatted string to date.  Sample String dates are as follows.

2014/12/21
20140214
2014/12/13
2014/12/23
20141201

We will write some java code to replace “/” with non. so below code will replace “/” with empty string “” and then parse date function convert it using given format.

Convert dates with time stamp.

  • Input String “2014-11-14T10:41:34-08:00″
  • Format  “yyyy-MM-dd’T’HH:mm:ssXXX”

  • Input String: “2013-09-03T21:54:32.027+02:00″
  • Format: “yyyy-MM-dd’T’HH:mm:ss.SSSX:00″

  •  Input String: “Tue May 08 00:00:00 CEST 2012″
  • Format: “EEE MMM dd HH:mm:ss zzz yyyy”

  • Input String: “30 Aug 2011 07:06:00″
  • Format: “dd MMM yyyy HH:mm:ss”

  •  Input String “24/02/2015 23:15:37.250000000″
  • Format: “dd/MM/yyyy HH:mm:ss.SSSS”

Parse DateTime-string with AM/PM marker

  • Input String : “12/20/2012 10:02 PM”
  • Format String: “MM/dd/yyyy HH:mm a”

If you have any other format which is not listed here, then please send us we will include in list.

Keep visiting this page for newer formats.

About Umesh

I am Software consultant with approx 7 years of experience mainly in Business Intelligence and data warehousing assignments using Talend. Writing is not my passion but i am doing it to help others. if you have any special case where you want me to demonstrate then please post me.

3 comments on “Convert String To Date

    1. It’s not possible. You cannot determine if 01/01/2013 is MM/dd/yyyy or dd/MM/yyyy if you dont know the real format beforehand

Leave a Reply to dwetl Cancel reply

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