Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

[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.
Labels (3)
1 Solution

Accepted Solutions
_AnonymousUser
Specialist III
Specialist III
Author

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.

View solution in original post

7 Replies
_AnonymousUser
Specialist III
Specialist III
Author

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.
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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?
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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.
Anonymous
Not applicable

Great...
Thanks James for this update

Vaibhav
_AnonymousUser
Specialist III
Specialist III
Author

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