One Star

[resolved] parseDate and combining date and time part from different columns.

Hello.
I'm trying to combine two different columns from
a delimited file into a one column.  The values look
"08.08.2014" and "13:57" and since I'm testing limiting
to one row only, those values really are in place.
Right now I'm using:
TalendDate.parseDate(TalendDate.formatDate("dd.MM.yyyy",row1.MYDATECOLUMN)+ " " + TalendDate.formatDate("HH:mm",row1.MyTIMECOLUMN), "dd.MM.yyyy HH:mm")

which gives me error:
Exception in component tMap_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "dd.MM.yyyy HH:mm"
    at routines.TalendDate.parseDate(TalendDate.java:864)

The formatDates apparently work since I can output
that combination as a string. Please help, after trying
too many times I seem blind to my own solutions.
By the way, do I need to state the length for that variable
in out1 and if I do what would the length be for example
for date patterns "dd.MM.yyyy" or "dd.MM.yyyy HH:mm"?
Those dates will eventually end up into a PostgreSQL db.
Thanks.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] parseDate and combining date and time part from different columns.

String date1="08.08.2014";
String date2 = "13:57";
String totDate = date1+" "+date2;
System.out.println(totDate);
TalendDate.parseDate("dd.MM.yyyy HH:mm",totDate));
Above works if both date and time are string..., else you need to do some manipulations...

OK, I got it, thank you.
Anyway, my final form of the solution for my problem, where
my date column row1.MYDATECOLUMN is in Date format and
time column row1.MYTIMECOLUMN is a String and I wanted
to combine them and convert to a Date:
So, first convert the Date part into a String with:

TalendDate.formatDate("dd.MM.yyyy", row1.MYDATECOLUMN)

then catenate the time part String to the end with:
 
+" "+row1.MYTIMECOLUMN

and use parseDate to convert the combined String into Date like:

TalendDate.parseDate("dd.MM.yyyy HH:mm", TalendDate.formatDate("dd.MM.yyyy", row1.MYDATECOLUMN)+" "+row1.MYTIMECOLUMN)

Thanks Vaibhav.
7 REPLIES
One Star

Re: [resolved] parseDate and combining date and time part from different columns.

And for some reason, just like the last time,
when I try to log in, it shows me my credentials
but I still need to fill in my name and email when
posting and get demoted to a guest.
Sorry about that. I need to look into it later.
Four Stars

Re: [resolved] parseDate and combining date and time part from different columns.

Hi James, 

first try concatenating both date fields and they try converting... like below (Below I am assuming both of your fields are string, if not, then first convert it to string, concatenate and assign to some string variable and then use that variable in below statement)

TalendDate.parseDate(TalendDate.formatDate("dd.MM.yyyy HH:mm",row1.MYDATECOLUMN+row1.MyTIMECOLUMN))

Vaibhav
One Star

Re: [resolved] parseDate and combining date and time part from different columns.

first try concatenating both date fields and they try converting... like below (Below I am assuming both of your fields are string, if not, then first convert it to string, concatenate and assign to some string variable and then use that variable in below statement)
TalendDate.parseDate(TalendDate.formatDate("dd.MM.yyyy HH:mm",row1.MYDATECOLUMN+row1.MyTIMECOLUMN))

Thank you but that did't work, since formatDate apparently
takes in (String, Date) and I'd have to first combine those
to columns into a Date, which is my main goal.
At first I was trying to read the columns in as Dates but
is it even possible to read in date format HH:mm?
Four Stars

Re: [resolved] parseDate and combining date and time part from different columns.

String date1="08.08.2014";
String date2 = "13:57";
String totDate = date1+" "+date2;
System.out.println(totDate);
TalendDate.parseDate("dd.MM.yyyy HH:mm",totDate));

Above works if both date and time are string..., else you need to do some manipulations...
Vaibhav
One Star

Re: [resolved] parseDate and combining date and time part from different columns.

String date1="08.08.2014";
String date2 = "13:57";
String totDate = date1+" "+date2;
System.out.println(totDate);
TalendDate.parseDate("dd.MM.yyyy HH:mm",totDate));
Above works if both date and time are string..., else you need to do some manipulations...

OK, I got it, thank you.
Anyway, my final form of the solution for my problem, where
my date column row1.MYDATECOLUMN is in Date format and
time column row1.MYTIMECOLUMN is a String and I wanted
to combine them and convert to a Date:
So, first convert the Date part into a String with:

TalendDate.formatDate("dd.MM.yyyy", row1.MYDATECOLUMN)

then catenate the time part String to the end with:
 
+" "+row1.MYTIMECOLUMN

and use parseDate to convert the combined String into Date like:

TalendDate.parseDate("dd.MM.yyyy HH:mm", TalendDate.formatDate("dd.MM.yyyy", row1.MYDATECOLUMN)+" "+row1.MYTIMECOLUMN)

Thanks Vaibhav.
Four Stars

Re: [resolved] parseDate and combining date and time part from different columns.

Great...
Thanks James for this update

Vaibhav
One Star

Re: [resolved] parseDate and combining date and time part from different columns.

This thread is resolved. Could someone with appropriate rights
mark this resolved as I being a guest cannot. Thank you.
JB