[resolved] Comparing Dates in tMap

Highlighted
One Star

[resolved] Comparing Dates in tMap

Hi All,
I have been trying to figure out why my tMap isn't comparing dates properly.
I have created a globalmap string called "testDate" and set it to "04/03/13" ("mm/dd/yy" format). This is using tSetGlobalVar
I am then reading a table from an Oracle db that has 3 fields: User ID (integer), Login (String), and LoginDate (Date)
The tOracleInput then goes to a tMap for processing.
The goal is to get all users whose LoginDate matches the global "testDate"
This is my tMap filter condition: TalendDate.compareDate(row1.LAST_LOGIN_DATE,TalendDate.parseDate("mm/dd/yy",(String)globalMap.get("testDate"))) == 0
Basically I am parsing the the global testDate as TalendDate and then comparing that to the row date from Oracle.
My filter returns 0 results even though there are users whose login date match the criteria.
Any help would be amazing, thank you so much!
I am attaching images of my job, it is quite simple.
Here is some sample data from the tLogRow when I remove the filter condition in the tMap:
15419|user1|20-11-12
15574|user2|13-06-12
15580|user3|02-10-12
15593|user4|26-06-12
15608|user5|06-11-12

Accepted Solutions
One Star

Re: [resolved] Comparing Dates in tMap

Hi, that one change did not fix it, however, it led me on the path to the solution.
I found that there is a second TalendDate.compareDate that lets you specify which parts of the date to compare, so it worked when I changed my expression to: TalendDate.compareDate(row1.LAST_LOGIN_DATE,TalendDate.parseDate("mm/dd/yy",(String)globalMap.get("testDate")),"dd-MM-yyy") == 0
Thanks for the assistance shong!

All Replies
One Star

Re: [resolved] Comparing Dates in tMap

Is the potential issue that I'm comparing row1.LAST_LOGIN_DATE which is of type Date with the result of a parseDate ?
Community Manager

Re: [resolved] Comparing Dates in tMap

Hi
This is my tMap filter condition: TalendDate.compareDate(row1.LAST_LOGIN_DATE,TalendDate.parseDate("mm/dd/yy",(String)globalMap.get("testDate"))) == 0

The date pattern should be "MM/dd/yy", MM presents month in a year, welll mm means minutes in a hour.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Comparing Dates in tMap

Hi, that one change did not fix it, however, it led me on the path to the solution.
I found that there is a second TalendDate.compareDate that lets you specify which parts of the date to compare, so it worked when I changed my expression to: TalendDate.compareDate(row1.LAST_LOGIN_DATE,TalendDate.parseDate("mm/dd/yy",(String)globalMap.get("testDate")),"dd-MM-yyy") == 0
Thanks for the assistance shong!

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog