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

Announcements
Streamlining user types in Qlik Cloud capacity-based subscriptions: Read the Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Convert date and empty date

Hi,
I have a problem in a tMap.
I read a RSS feed with pubdate in GMT or CEST Time.
My colum table is a DATETIME type.
1. How to convert GMT to DATETIME ?
2. CEST is not read by tRSSInput. So, How to insert datetime.now if pubdate is empty ?
Thanks in advance.
Regards
Labels (2)
1 Solution

Accepted Solutions
alevy
Specialist
Specialist

There are a number of problems with your expressions:
1. parseDate converts a String to a Date i.e. the second parameter of parseDate must be a date string as you have correctly used it in your last post. TalendDate.getCurrentDate(), however, already returns a Date so does not need to have parseDate applied to it.
2. In any case, since it is a function, getCurrentDate should not be enclosed in quotes otherwise you are trying to parse an actual String containing the words "TalendDate.getCurrentDate()".
3. If you actually wanted the current date as a String, you could use e.g. TalendDate.getDate("yyyy-MM-dd HH:mm:ss")
4. From the error, it appears that row1.PUBDATE contains the String "20 Jul 2011 11:50:00 GMT", which obviously cannot be parsed to a Long since it is not a whole number. You should simply be parsing it directly to a Date.
i.e.
row1.PUBDATE.isEmpty()
? TalendDate.getCurrentDate()
: TalendDate.parseDate("dd MMM yyyy HH:mm:ss zzz",row1.PUBDATE)

View solution in original post

17 Replies
Anonymous
Not applicable
Author

Nobody can help me ?
Anonymous
Not applicable
Author

For the empty date I tried this :
(row1.PUBDATE.isEmpty())
? TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","TalendDate.getCurrentDate()")
:row1.PUBDATE
but don't working 0683p000009MPcz.png
Anonymous
Not applicable
Author

I tried this :
(row1.PUBDATE.isEmpty())
? TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","2011-07-30 12:51:12")
: new java.util.Date(Long.parseLong(row1.PUBDATE))
But when the job is on the first GMT date, the error is :
Exception in component tMap_1
java.lang.NumberFormatException: For input string: "20 Jul 2011 11:50:00 GMT"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at mediascit.recupflux_0_1.RecupFlux.tMysqlInput_1Process(RecupFlux.java:1246)
at mediascit.recupflux_0_1.RecupFlux.runJobInTOS(RecupFlux.java:1708)
at mediascit.recupflux_0_1.RecupFlux.main(RecupFlux.java:1579)
And : How can I have the currentdate in place of "2011-07-30 12:51:12" ? getCurrentDate don't work 0683p000009MPcz.png
alevy
Specialist
Specialist

There are a number of problems with your expressions:
1. parseDate converts a String to a Date i.e. the second parameter of parseDate must be a date string as you have correctly used it in your last post. TalendDate.getCurrentDate(), however, already returns a Date so does not need to have parseDate applied to it.
2. In any case, since it is a function, getCurrentDate should not be enclosed in quotes otherwise you are trying to parse an actual String containing the words "TalendDate.getCurrentDate()".
3. If you actually wanted the current date as a String, you could use e.g. TalendDate.getDate("yyyy-MM-dd HH:mm:ss")
4. From the error, it appears that row1.PUBDATE contains the String "20 Jul 2011 11:50:00 GMT", which obviously cannot be parsed to a Long since it is not a whole number. You should simply be parsing it directly to a Date.
i.e.
row1.PUBDATE.isEmpty()
? TalendDate.getCurrentDate()
: TalendDate.parseDate("dd MMM yyyy HH:mm:ss zzz",row1.PUBDATE)
Anonymous
Not applicable
Author

Hi,
I resolved my problem last night.
It's the good solution.
Thanks.
Anonymous
Not applicable
Author

I discovered a bug :
My job working in my Studio but don't work in production after publication.
Error : Data truncation: Incorrect datetime value: '20 Jul 2011 23:00:00 GMT' for column 'date' at row 1
Error : Data truncation: Incorrect datetime value: '21 Jul 2011 08:37:35 GMT' for column 'date' at row 1
Error : Data truncation: Incorrect datetime value: '21 Jul 2011 07:18:00 GMT' for column 'date' at row 1
The database and tables are the same ...
Any idea ?
alevy
Specialist
Specialist

It looks like you're trying to pass the original row1.PUBDATE String to the database without parsing it to a Date.
Anonymous
Not applicable
Author

(row1.PUBDATE.isEmpty())
? TalendDate.currentDate()
: TalendDate.parseDate("dd MMM yyyy HH:mm:ss",row1.PUBDATE.substring(0,row1.PUBDATE.indexOf("G")-1))
The currentDate() return a datetime or a string ???
My database column is DATETIME format.
Anonymous
Not applicable
Author

Back from holidays ...
My function :
(row7.PUBDATE.isEmpty())
? TalendDate.currentDate()
: TalendDate.parseDate("dd MMM yyyy HH:mm:ss",row7.PUBDATE.substring(0,row7.PUBDATE.indexOf("G")-1))
Error message :
La méthode currentDate() est indéfinie pour le type TalendDate
Any idea ?
Thanks in advance