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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

CHANGE DATE FORMAT WITH BLANK ROWS

Hi,

I am trying to convert a string that acts as an input with date format "EEE MMM dd HH:mm:ss Z yyyy" into the format "dd/MM/yyyy", avoiding the existing blank rows.  I found the following command to do it:

 

TalendDate.isDate(row1.Fecha_de_Llegada_Real,"EEE MMM dd HH:mm:ss Z yyyy")? TalendDate.parseDate("dd/MM/yyyy",row1.Fecha_de_Llegada_Real) : null

 

Although I am 100% sure this is the correct input format, as when printing this row as a string I obtain strings like "Wed Jan 02 00:00:00 CET 2019", I get all null because all the values of the TalendDate.isDate() give a false value.

 

Any idea why this is heppening?

Thank you so much

 

 

 

 

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

In the end it was easier than what we thought, but thanks to the beginning of your last code was the key, as by using:

row1.Fecha_de_Llegada_Real!=null ? TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss z yyyy",row1.Fecha_de_Llegada_Real,"EN") : null, worked perfectly.

 

Thank you so much!

View solution in original post

5 Replies
Anonymous
Not applicable
Author

There were a couple of issues in this. The way to get what you want is shown below....

 

TalendDate.isDate(row1.Fecha_de_Llegada_Real,"EEE MMM dd HH:mm:ss z yyyy")? TalendDate.formatDate("dd/MM/yyyy", TalendDate.parseDate("EEE MMM dd HH:mm:ss z yyyy",row1.Fecha_de_Llegada_Real)) : null

The first error was the format. You used Z instead of z.

 

There was another omission though. In order to change the output format, you need to first convert the String to a Date. THEN you can format it to "dd/MM/yyyy".

 

The above code should work for you. 

Anonymous
Not applicable
Author

Thanks for the reply. You are right when changing the output format.

Unfortunately, the first change didn't work as expected. Changing the capital z did not make any change to the result of getting all false. Actually, I found some strange error when trying to parse the date as when using:

 

TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss z yyyy",row1.Fecha_de_Llegada_Real,"EN"), it works perfectly until it finds a null, obviously showing a NullPointerException, while using:

 

TalendDate.parseDate("EEE MMM dd HH:mm:ss z yyyy",row1.Fecha_de_Llegada_Real), it says that it is an Unparseable date, and using your proposed expression:

 

TalendDate.formatDate("dd/MM/yyyy", TalendDate.parseDate(
"EEE MMM dd HH:mm:ss z yyyy", row1.Fecha_de_Llegada_Real)), it

appears a mismatch error saying that "cannot convert from String to Date", I guess as a consequence of the previous error.

 

I know it does not make sense, that's why my confusion.

 

 

Anonymous
Not applicable
Author

Ah, I see. Sorry I neglected to include a check for a null input. You need to use this....

 

row1.Fecha_de_Llegada_Real!=null ?(TalendDate.isDate(row1.Fecha_de_Llegada_Real,"EEE MMM dd HH:mm:ss z yyyy")? TalendDate.formatDate("dd/MM/yyyy", TalendDate.parseDate("EEE MMM dd HH:mm:ss z yyyy",row1.Fecha_de_Llegada_Real)) : null) : null

I've simply added a check for the input value (or lack of). If your data comes in as null, you cannot perform String to Date conversion since null is nothing (not a String). The above should work.

 

The Z to z is the difference between.....

 

z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

 

Anonymous
Not applicable
Author

In the end it was easier than what we thought, but thanks to the beginning of your last code was the key, as by using:

row1.Fecha_de_Llegada_Real!=null ? TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss z yyyy",row1.Fecha_de_Llegada_Real,"EN") : null, worked perfectly.

 

Thank you so much!

Anonymous
Not applicable
Author

I'm glad that works, but that will not change the format, that converts your Sting into a Date. I suspect your output column is a Date type and by default has the correct String output format. It is important to recognise the difference here 🙂