<?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: Help with a formula in script: Time Difference in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374304#M139304</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hope you have seen my edit in my last post. Just tested with a couple of timestamps and it seemed to work (well, there is a typo in the createdonPart1 line, remove the comma after the frac() function ).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jun 2012 12:10:58 GMT</pubDate>
    <dc:creator>swuehl</dc:creator>
    <dc:date>2012-06-29T12:10:58Z</dc:date>
    <item>
      <title>Help with a formula in script: Time Difference</title>
      <link>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374300#M139300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two date fields called createdon and modifiedon. The formats are both dd/mm/yyyy hh:mm in a table and in the script I want to calculate the time difference between the two. I want it to report the time difference in hh:mm. Can someone help me out with a forumla please? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, part 2 (if possible): If the difference between the two is &amp;gt; 4 hours then I want it to return the value 2:00 (2 hours). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, and this is the really tricky bit - can I get the formula to only calculate the difference between the hours of 9am and 5pm? i.e. If the record was createdon 26/06/2012 16:30 and modified on 27/06/2012 at 9:30 then I want it to return a result of 01:00 (1 hour) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any takers? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stuart&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 10:39:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374300#M139300</guid>
      <dc:creator>stuwannop</dc:creator>
      <dc:date>2012-06-29T10:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a formula in script: Time Difference</title>
      <link>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374301#M139301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First, set your default timestamp format to &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;SET TimestampFormat='DD/MM/YYYY hh:mm';&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or use timestamp#() function to interprete your timestamp fields correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, you can calculate the difference of both fields (if located in one table) and use interval to format accordingly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;createdon,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;modifiedon,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;interval(if( (modified - createdon) &amp;gt; maketime(4),maketime(2), modifiedon - createdon), 'hh:mm') as TimeDiff,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;FROM ...;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your last request is a bit more tricky, but I think there were some similar threads quite recently, just search the forum. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or try something like this (untested):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD *,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;interval( if(TimeDiffPart1 &amp;gt; maketime(4),maketime(2), TimeDiffPart1), 'hh:mm') as TimeDiff;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;LOAD *,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if(floor(modifiedon) &amp;gt; floor(createdon), createdonPart1+modifiedonPart1, modifiedon - createdon) as TimeDiffPart1;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;createdon,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;modifiedon,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;maketime(17)-frac(createdon), as createdonPart1,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;frac(modifiedon) - maketime(9) as modifiedonPart1&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;FROM ...;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 11:03:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374301#M139301</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-06-29T11:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a formula in script: Time Difference</title>
      <link>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374302#M139302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many thanks for the prompt response! I will give that a go and let you know how I get on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 11:16:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374302#M139302</guid>
      <dc:creator>stuwannop</dc:creator>
      <dc:date>2012-06-29T11:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a formula in script: Time Difference</title>
      <link>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374303#M139303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Worked a treat - thanks a lot - now for the tricky bit.... &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 12:03:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374303#M139303</guid>
      <dc:creator>stuwannop</dc:creator>
      <dc:date>2012-06-29T12:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help with a formula in script: Time Difference</title>
      <link>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374304#M139304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hope you have seen my edit in my last post. Just tested with a couple of timestamps and it seemed to work (well, there is a typo in the createdonPart1 line, remove the comma after the frac() function ).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2012 12:10:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-with-a-formula-in-script-Time-Difference/m-p/374304#M139304</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-06-29T12:10:58Z</dc:date>
    </item>
  </channel>
</rss>

