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

Error while comparing TalendDate with database date column

Hi,
I have my database date columns storing datetime in the format 'YYYY-MM-DD HH:mi:ss:mmm'
I want the talend current date to be returned in this format. So , I used this TalendDate.formatDate("YYYY-mm-dd HH:mm:ss",TalendDate.parseDate("YYYY-mm-dd HH:mm:ss",TalendDate.getDate("YYYY-mm-dd HH:mm:ss")))
The problem is this is converting it to string. Also, I keep getting the error 'Incorrect syntax' when I pass the above to sql. And hence I cannot compare with date column of the database.
Am using sql server
Any thougths on this?
Thanks
Rathi
Labels (2)
6 Replies
TRF
Champion II
Champion II

Hi,
Get the current Talend date using this syntax:
TalendDate.formatDate("yyyy-MM-dd HH:mm:ss:SSS",TalendDate.getCurrentDate())

Get the date from SQL Server using this syntax in your SQL query:
CONVERT(VARCHAR(24), yourColumnDate, 121)

Check the result on the SQL Server before (I'm not sure for this point).
Now you have 2 strings you can compare.
Hope this helps.
TRF
Anonymous
Not applicable
Author

Hi TRF, thanks for the response
I need to compare the dates. >= , <= etc. With strings I would not be able to achieve this. Is there any way to do this?
Thanks
Rathi
TRF
Champion II
Champion II

row1.yourTalendDate.compareTo(row2.yourSqlDate)
// return 0, < 0 or > 0 depending of the comparison result
Anonymous
Not applicable
Author

Thanks TRF. That will work.
I have to pass the talendate as a parameter to a function. The function in sql server only understands data as date. How do I do this?
TRF
Champion II
Champion II

Try "CAST" when calling the SQL function.
Anonymous
Not applicable
Author

Ok. I have a tsetglobalvar whose value is var = TalendDate.getDate("YYYY-MM-dd HH:mm:ss:mmm").
Now I need to pass this to tmssqlinput. How do I do this? The query in tmssqlinput is "select * from function("+globalMap.var+)"
I am trying to pass with cast and convert, but still keeps giving syntax error
Thanks
Rathi