<?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 Re: date difference formula in qliksense load script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004303#M83142</link>
    <description>&lt;P&gt;The solution appears to be the generous application of single quotes:&lt;/P&gt;
&lt;P&gt;,if('$(vEndDate)' - Date &amp;lt;=7 and '$(vEndDate)' - Date &amp;gt;= 1, 1) as Last7d&lt;BR /&gt;,if('$(vEndDate)' - Date &amp;lt;=28 and '$(vEndDate)' - Date &amp;gt;= 1, 1) as Last4w&lt;BR /&gt;,if(MonthStart(Date) = MonthStart(AddMonths('$(vEndDate)',-1)),MonthName(Date)) as PreviousMonth&lt;BR /&gt;,if('$(vEndDate)'-Date &amp;lt;=180 and '$(vEndDate)'-Date &amp;gt;= 1, 1) as Last6Months&lt;/P&gt;
&lt;P&gt;I did not try interval because the documentation says that is a formatting function.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2022 20:48:24 GMT</pubDate>
    <dc:creator>daveatkins</dc:creator>
    <dc:date>2022-11-14T20:48:24Z</dc:date>
    <item>
      <title>date difference formula in qliksense load script</title>
      <link>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004219#M83136</link>
      <description>&lt;P&gt;Can someone explain the correct syntax for this simple edit to a load script? My immediate problem is with the attempt to calculate the date diff to set a flag for Last7d.&lt;/P&gt;
&lt;P&gt;"Date" is a field in the data which is also a date type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let vStartDate = date('5/1/2022');&lt;BR /&gt;Let vEndDate = date(WeekEnd(Today()-7)); //last Saturday&lt;/P&gt;
&lt;P&gt;LOAD *&lt;BR /&gt;//,if(Today()-Date &amp;lt;=7 and Today()-Date&amp;gt;=1, 1) as Last7d&amp;nbsp; &amp;nbsp; &amp;nbsp; //works&lt;BR /&gt;,if($(vEndDate) - Date &amp;lt;=7 and $(vEndDate) - Date &amp;gt;= 1, 1) as Last7d&amp;nbsp; //generalizing&lt;/P&gt;
&lt;P&gt;,$(vEndDate) - Date as DaysDiff //debugging&lt;BR /&gt;,if(Today()-Date &amp;lt;=28 and Today()-Date&amp;gt;=1, 1) as Last4w&lt;BR /&gt;,if(MonthStart(Date) = MonthStart(AddMonths(Today(),-1)),MonthName(Date)) as PreviousMonth&lt;BR /&gt;,if(Today()-Date &amp;lt;=180 and Today()-Date &amp;gt;= 1, 1) as Last6Months&lt;BR /&gt;,ApplyMap('RegionMap', Corp,'No Region Mapped') As Region&lt;BR /&gt;Resident FactTable&lt;BR /&gt;WHERE Date &amp;lt;= Today()-1&lt;BR /&gt;and Date &amp;gt;= '$(vStartDate)';&lt;/P&gt;
&lt;P&gt;I understand why this fails; it interprets the variable by dividing day, year, etc. so the result is 0.0something - a date resulting in -44875 as the value of the operation.&lt;/P&gt;
&lt;P&gt;If I take away the $() then no field found.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is seriously no logical rationale to how Qlik handles dates. I have still not figured it out after 9 years. Always trial and error. The where clause above works but is logically inconsistent. $() should be returning a date...why are single quotes needed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 16:04:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004219#M83136</guid>
      <dc:creator>daveatkins</dc:creator>
      <dc:date>2022-11-14T16:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: date difference formula in qliksense load script</title>
      <link>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004273#M83138</link>
      <description>&lt;P&gt;Interval('$(vEndDate)' - Date,'dd') as DaysDiff&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 19:04:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004273#M83138</guid>
      <dc:creator>BrunPierre</dc:creator>
      <dc:date>2022-11-14T19:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: date difference formula in qliksense load script</title>
      <link>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004303#M83142</link>
      <description>&lt;P&gt;The solution appears to be the generous application of single quotes:&lt;/P&gt;
&lt;P&gt;,if('$(vEndDate)' - Date &amp;lt;=7 and '$(vEndDate)' - Date &amp;gt;= 1, 1) as Last7d&lt;BR /&gt;,if('$(vEndDate)' - Date &amp;lt;=28 and '$(vEndDate)' - Date &amp;gt;= 1, 1) as Last4w&lt;BR /&gt;,if(MonthStart(Date) = MonthStart(AddMonths('$(vEndDate)',-1)),MonthName(Date)) as PreviousMonth&lt;BR /&gt;,if('$(vEndDate)'-Date &amp;lt;=180 and '$(vEndDate)'-Date &amp;gt;= 1, 1) as Last6Months&lt;/P&gt;
&lt;P&gt;I did not try interval because the documentation says that is a formatting function.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 20:48:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/date-difference-formula-in-qliksense-load-script/m-p/2004303#M83142</guid>
      <dc:creator>daveatkins</dc:creator>
      <dc:date>2022-11-14T20:48:24Z</dc:date>
    </item>
  </channel>
</rss>

