<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Date Java issue in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269493#M47721</link>
    <description>Hello !
&lt;BR /&gt;This drives me crazy !!!!
&lt;BR /&gt;I'm trying to define 2 java functions, one to calculate the numbers of days between 2 dates, one to add a certain number of days to a date.
&lt;BR /&gt;Here are my functions:
&lt;BR /&gt;
&lt;PRE&gt;    public static int getDateDifferenceInDays (Date firstDate, Date secondDate) {&lt;BR /&gt;    	long diff;&lt;BR /&gt;    	diff = secondDate.getTime() - firstDate.getTime();&lt;BR /&gt;    	diff /= (24L * 3600L * 1000L);&lt;BR /&gt;    	return (int)diff; &lt;BR /&gt;    }&lt;BR /&gt;    public static Date addNumberOfDays (Date referenceDate, int numberOfDays) {&lt;BR /&gt;    	  long diff, toAdd;&lt;BR /&gt;    	  Date result;&lt;BR /&gt;    	  diff = referenceDate.getTime();&lt;BR /&gt;    	  diff += numberOfDays * 24L * 3600L * 1000L;&lt;BR /&gt;    	  result.setTime(diff);&lt;BR /&gt;    	  return result;     	 &lt;BR /&gt;    }&lt;/PRE&gt;
&lt;BR /&gt;When I test the functions, by calculating the difference between today and a date to 2009-03-29 it works.
&lt;BR /&gt;BUT, when I calculate '2009-03-30' - '2009-02-17' it give 40 days (instead of 41)....
&lt;BR /&gt;I think this is because of a round error (during cast), but... how can I do ??
&lt;BR /&gt;Thanks
&lt;BR /&gt;Arnaud</description>
    <pubDate>Sat, 16 Nov 2024 14:04:22 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-16T14:04:22Z</dc:date>
    <item>
      <title>Date Java issue</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269493#M47721</link>
      <description>Hello !
&lt;BR /&gt;This drives me crazy !!!!
&lt;BR /&gt;I'm trying to define 2 java functions, one to calculate the numbers of days between 2 dates, one to add a certain number of days to a date.
&lt;BR /&gt;Here are my functions:
&lt;BR /&gt;
&lt;PRE&gt;    public static int getDateDifferenceInDays (Date firstDate, Date secondDate) {&lt;BR /&gt;    	long diff;&lt;BR /&gt;    	diff = secondDate.getTime() - firstDate.getTime();&lt;BR /&gt;    	diff /= (24L * 3600L * 1000L);&lt;BR /&gt;    	return (int)diff; &lt;BR /&gt;    }&lt;BR /&gt;    public static Date addNumberOfDays (Date referenceDate, int numberOfDays) {&lt;BR /&gt;    	  long diff, toAdd;&lt;BR /&gt;    	  Date result;&lt;BR /&gt;    	  diff = referenceDate.getTime();&lt;BR /&gt;    	  diff += numberOfDays * 24L * 3600L * 1000L;&lt;BR /&gt;    	  result.setTime(diff);&lt;BR /&gt;    	  return result;     	 &lt;BR /&gt;    }&lt;/PRE&gt;
&lt;BR /&gt;When I test the functions, by calculating the difference between today and a date to 2009-03-29 it works.
&lt;BR /&gt;BUT, when I calculate '2009-03-30' - '2009-02-17' it give 40 days (instead of 41)....
&lt;BR /&gt;I think this is because of a round error (during cast), but... how can I do ??
&lt;BR /&gt;Thanks
&lt;BR /&gt;Arnaud</description>
      <pubDate>Sat, 16 Nov 2024 14:04:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269493#M47721</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T14:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date Java issue</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269494#M47722</link>
      <description>hi,&lt;BR /&gt;perhaps you could find some "good methods" &lt;A href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Calendar class&lt;/A&gt; in Calendar class like add() method (to add and substract).&lt;BR /&gt;but not sure about it&lt;BR /&gt;++</description>
      <pubDate>Tue, 17 Feb 2009 16:46:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269494#M47722</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-02-17T16:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Date Java issue</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269495#M47723</link>
      <description>Google is your friend:&lt;BR /&gt;&lt;A href="http://www.google.com/search?num=100&amp;amp;hl=en&amp;amp;safe=active&amp;amp;q=java+add+days+to+date" target="_blank" rel="nofollow noopener noreferrer"&gt;search: java add days to date&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.google.com/search?num=100&amp;amp;hl=en&amp;amp;safe=active&amp;amp;q=java+days+between+2+dates" target="_blank" rel="nofollow noopener noreferrer"&gt;search: java days between 2 dates&lt;/A&gt;&lt;BR /&gt;Your answer is there for the taking.&lt;BR /&gt;StijnM.</description>
      <pubDate>Wed, 18 Feb 2009 06:53:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269495#M47723</guid>
      <dc:creator>_AnonymousUser</dc:creator>
      <dc:date>2009-02-18T06:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Date Java issue</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269496#M47724</link>
      <description>Yes, it is... but it can also give me some results that looks good at first sight ! 
&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt; I found many examples where the difference was good if the number of days was less than 40 days, but, when I tried with a date difference that should be 41 days, I got a wrong result (40). 
&lt;BR /&gt;But, I finally found, in the results of your keywords (different from mine). My problem was a round error, solved by adding an hour... 
&lt;BR /&gt;Thank you StijnM</description>
      <pubDate>Wed, 18 Feb 2009 07:40:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Date-Java-issue/m-p/2269496#M47724</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-02-18T07:40:59Z</dc:date>
    </item>
  </channel>
</rss>

