One Star

How to split the date from date and time

Hi,
In my flat file i am having date in the format of yyyy-MM-dd HH:mm:ss.SSS.For example "2009-02-24 00:00:00.000".My requirement is getting date alone in the format of MM/dd/yyy.By using tmap how to do?Any one please give me reply.
Thanks
Jyothsna.E
7 REPLIES
Community Manager

Re: How to split the date from date and time

Hello
You can read the date as a string, then substring the string and parse the result to a date finally.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to split the date from date and time

Hi
As per you i given like this "TalendDate.parseDate("MM/dd/yyyy",DataFile1.LOSS_DT.substring(0, 10) )".But it is not working.How to go give the condition?
Community Manager

Re: How to split the date from date and time

Hello
See the screenshot.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to split the date from date and time

Hi
I saw you screen shot.I also given like this "TalendDate.parseDate("MM/dd/yyyy",DataFile1.LOSS_DT.substring(0, 10) )".It showing error like
Exception in component tMap_2
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "2005-01-02".
Seventeen Stars

Re: How to split the date from date and time

hi,
I'm not sure about whazt you are looking for , but if you just want to get a result string from your substring,
you can do something like :
String [] arr = sub.split("-"); 
String newDate = arr+"/"+arr+"/"+arr;

but if you want Date type , I think you 've to use SimpleDateFormat
hope it help you
++
ps:hoops ... too slowly answer Smiley Happy
Community Manager

Re: How to split the date from date and time

Hello
Hi
I saw you screen shot.I also given like this "TalendDate.parseDate("MM/dd/yyyy",DataFile1.LOSS_DT.substring(0, 10) )".It showing error like
Exception in component tMap_2
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "2005-01-02".

Your expression is not like mine, please see my screenshot again.
The correct expression should be:
TalendDate.parseDate("yyyy-MM-dd",DataFile1.LOSS_DT.substring(0, 10) )

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to split the date from date and time

Hi Shong,
I am having a similar scenario & Your solution is not working for me.In my job Tmap rejects these records.Also my Date format in the input csv is "MM/dd/yyyy HH:mm:ss" .So in the expression should we specify "MM/dd/yyyy" or "MM/dd/yyyy HH:mm:ss".Please reply asap.Thanks in advance.