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: 
peterko
Contributor III
Contributor III

Compare Dates

Hello,
how do I compare two dates?
I would like something like this in my tMap:
TalendDate.compareDate(TalendDate.getDate("dd-MM-yyyy"), row1.service_date, "dd-MM-yyyy") > 0 ? TalendDate.getDate("dd-MM-yyyy") : row1.service_date

where row1.service_date is a date, and I save the result to columns of type date.
But I still writes error "Exception in thread" main "java.lang.Error: unresolved compilation problems"
Labels (3)
11 Replies
Anonymous
Not applicable

The method  TalendDate.getDate("dd-MM-yyyy") returns a string, not a Date. Try this expression:
TalendDate.compareDate(TalendDate.getCurrentDate(), row1.service_date)>0?TalendDate.getCurrentDate(): sOrders.serviced_at


Best regards
Shong
peterko
Contributor III
Contributor III
Author

I'm constantly throwing error:
0683p000009MEeQ.png 
Anonymous
Not applicable

Hi,
If you test in tMap for your incoming data, then this error may come... whether same error appears after executing complete job?
Vaibhav
peterko
Contributor III
Contributor III
Author

TalendDate.compareDate(TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd")), row1.service_date, "yyyy-MM-dd") > 0 ? TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd")) : row1.service_date 

When I run it out of tMap, then is not error.
But comparison is not correct. I have always found it assigns the current date and not older.
Anonymous
Not applicable

Hi,
I have checked with fixedflowinput-->tJavaRow and date set to 2014-06-01 and 2014-08-01 with following code
System.out.println(TalendDate.compareDate(TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd")), input_row.service_date, "yyyy-MM-dd") > 0 ? TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd")) : input_row.service_date);
This works... i get expected results with those values...
Thanks
Vaibhav
peterko
Contributor III
Contributor III
Author

My date in the stream is in the format DD-MM-YYYY, but for comparison, I set the pattern "yyyy-MM-dd" 
I do not know why that compares first at the level of the day, then months, and finally to year. . 
How should I have a set pattern in the stream compared to me right?
Or what could be wrong?
Anonymous
Not applicable

You will have to stick to the incoming date format.... for comparison, talend will not care what format you have... Set any standard format and you get proper results... Metadata must match.
Vaibhav
peterko
Contributor III
Contributor III
Author

When I have everything in the same format "dd-MM-yyyy", as well as to compare it first to the day level, at the level of the month, and eventually to the level a year. For example, the date1 is 15-05-2010 and date2 is 15-01-2014, as earlier is evaluated date2.
Format "dd-MM-yyyy" for stream I got like a "Retrieve schema" from database connection.
Anonymous
Not applicable

TalendDate.compareDate(TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd")), row1.service_date, "yyyy-MM-dd") > 0 ? TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd")) : row1.service_date 

When I run it out of tMap, then is not error.
But comparison is not correct. I have always found it assigns the current date and not older.

TalendDate.getDate() returns the current date, do there exists service_date in your input data bigger than current date? if not, it is normal with this expression, it always output the current date.
Best regards
Shong