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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Wrong result for difference between two dates.

Hi,
I have a scenario, in which I should be calculating the difference between two dates (date format MM-dd-yyyy). 

I tried doing this using TalendDate.diffDate(Date1 ,Date2), but I am getting different results for different dates. 
For Example: TalendDate.diffDate("12-31-2015 ,"12-01-2015") the result is 30(correct), but for TalendDate.diffDate("03-31-2015 ,"03-01-2015") the result is 29 (wrong), similarly for some other dates. The results should be long or integer.

In the job I designed, the start and end dates are calculated in the job itself based on other dates in some cases and in some cases, we extract dates from database. Both the cases the issue is same.

I tried few other solutions which were provided in the forum, but it didn't help me.

Please help me out.

Thanks,
Bharath

Labels (2)
5 Replies
Anonymous
Not applicable
Author

As you're passing Strings, you're depending on default formats and may be falling foul of Java's Lenient Date Parsing.
Have you tried passing the date format as a parameter, or converting to Date type first?
Anonymous
Not applicable
Author

Hello,
I tried with TalendDate.diffDateIgnoreDST and the result seems to be ok for your examples.
DST means Daylight saving time.
If you want to know more about it, Google is your friend. 0683p000009MA9p.png
I hope it helps you.
Anonymous
Not applicable
Author

Hi Tdz,
Thanks for the help. It worked!!

Thanks,
Bharath
Anonymous
Not applicable
Author

Hello Bharath,
You're welcome.
You can mark this post as "resolved". 0683p000009MA9p.png
Anonymous
Not applicable
Author

There is an undocumented parameter to diffDate to handle this. Set ignoreDST as appropriate.


public static long diffDate(Date date1, Date date2, String dateType, boolean ignoreDST)