<?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: Calculating duration between two times over different dates- where timestamp is inaccurate in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255572#M870395</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I considered that. In my situation, there is no business case for a duration over 24 hours, but I would be interested in a solution which would accommodate that condition. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Dec 2016 12:48:48 GMT</pubDate>
    <dc:creator>jason_nicholas</dc:creator>
    <dc:date>2016-12-02T12:48:48Z</dc:date>
    <item>
      <title>Calculating duration between two times over different dates- where timestamp is inaccurate</title>
      <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255568#M870391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My source data Excel sheet maintains the [Booking Date], [Start Time], and [End Time] in different fields. However, The [Start Time] and [End Time] fields contain a default time stamp date of 1/1/1900. As such, if I have a booking which starts on one date and ends on the next, both Qlikview and Excel treat the data as if the [Start Time] is later than the [End Time], and calculating duration between the two doesn't produce very good results. In addition, I do not have an end date for the booking, from which to create a new timestamp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;[Booking Date] 11/29/2016&lt;/P&gt;&lt;P&gt;[Start Time] 1/1/1900 11:00:00 PM&lt;/P&gt;&lt;P&gt;[End Time] 1/1/1900 9:00:00 AM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;EM&gt;(but actually 9am the next morning. &lt;/EM&gt;&lt;EM&gt;there is no field which shows that the end date is on 11/30/2016)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried to eliminate the default date so I just have a time to work with:&lt;/P&gt;&lt;P&gt;Time(Frac([Start Time]),'hh:mm') as [Start]&amp;nbsp; &lt;EM&gt;(and also for [End Time])&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and adding a preceding load, for a result of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;interval([End]-[Start],'hh:mm') as [Duration];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load&amp;nbsp; [Booking ID],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Booking Date],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time(Frac([Start Time],'hh:mm')as [Start],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time(Frac([End Time],'hh:mm') as [End]&lt;/P&gt;&lt;P&gt;From (source doc.xls)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I format the [Duration] field as "Time", I get the results I am looking for VISUALLY, but it will not calculate correctly. In the example above, the Duration shows as 10:00 when set to Time (with seconds removed) but as -14:00 as interval. If I create a chart which calculates Sum([Duration])&lt;EM&gt;&amp;nbsp; (for all entries over a month, but in this case filtered to the single entry) &lt;/EM&gt;I get an interval display of 0:00 and a time display of 12:00. Either way, I cannot get the sum to equal 10 hours. If I have two of them, the sum doesn't equal 20 hours.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have also tried changing my chart format to:&lt;/P&gt;&lt;P&gt;if([Duration]&amp;gt;0,[Duration],Sum([Duration]+24))&amp;nbsp; &lt;EM&gt;(alternately, I replaced 24 with 86400, thinking it was looking for seconds)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This got me nowhere, as I expect I have the syntax all wrong to make this work. I am not sure this is the right direction, anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you tell me how I could create a duration field which can correctly calculate hours over two dates, when the timestamp does not provide accurate dates? The final result I am looking for is a chart which calculates the sum total of all durations (ideally, in minutes only) in a given month.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; It may be worth noting that I would prefer to load my [Booking Date] as Year([Booking Date]) as Month, Month([Booking Date]) as Month, etc., rather than as a single field. I simplified it for my example and my testing. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255568#M870391</guid>
      <dc:creator>jason_nicholas</dc:creator>
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating duration between two times over different dates- where timestamp is inaccurate</title>
      <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255569#M870392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe I have solved it. I would appreciate any error correction this board can provide.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;if([End]&amp;gt;[Start],[End]-[Start],[End]-[Start]+1) as Duration&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load&amp;nbsp; [Booking ID],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Year[Booking Date] as Year,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month[Booking Date] as Month,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Day[Booking Date] as Day,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time(Frac([Start Time],'ss')as [Start],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time(Frac([End Time],'ss') as [End]&lt;/P&gt;&lt;P&gt;From (source doc.xls)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By changing all of the time to seconds, it was much easier to see how the calculations were done. That is how I figured out it was '1' that I needed to indicate a 24 hour period. by subtracting an (apparent) later time from an (apparent) earlier time, I get a negative number. Adding a day to that gives me the appropriate difference between the actual times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From here, I set my Field displays back to interval 'hh:mm' so that the Start and End time read like a 24 hour clock and the Duration field reads as hours and minutes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A straight table chart with Month as a dimension and sum(duration) as the calculated dimension gives me a layout where each month is followed by the total of all durations within that month. I set the Duration display to Interval 'mm' and I have a total number of minutes across all Booking IDs in a given month.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a given month, I might&amp;nbsp; have 300 bookings with hundreds of hours, so it has been difficult to error check. I have grabbed subsets of data and it appears to be working, but if someone identifies an obvious error, I would be eternally grateful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2016 19:46:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255569#M870392</guid>
      <dc:creator>jason_nicholas</dc:creator>
      <dc:date>2016-11-30T19:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating duration between two times over different dates- where timestamp is inaccurate</title>
      <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255570#M870393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I could be missing something, but what you've done looks right to me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2016 21:18:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255570#M870393</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2016-11-30T21:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating duration between two times over different dates- where timestamp is inaccurate</title>
      <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255571#M870394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;QV internally stores a timestamp as a floating point value, the integer part is coding the date (days since 30 Dec 1899), the fractional part the time (i.e. 0.25 is coding 6 AM, 0.333333 is coding 8 AM, 0.75&amp;nbsp; --&amp;gt; 6 PM etc.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One thing to consider maybe:&lt;/P&gt;&lt;P&gt;Could a business case happen where real duration is more than 24 hours?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2016 21:20:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255571#M870394</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2016-11-30T21:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating duration between two times over different dates- where timestamp is inaccurate</title>
      <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255572#M870395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I considered that. In my situation, there is no business case for a duration over 24 hours, but I would be interested in a solution which would accommodate that condition. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2016 12:48:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255572#M870395</guid>
      <dc:creator>jason_nicholas</dc:creator>
      <dc:date>2016-12-02T12:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating duration between two times over different dates- where timestamp is inaccurate</title>
      <link>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255573#M870396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That would be hard without somehow encoding this case in your data, i.e. as long as your end timestamp is not really showing the date (or better: showing the real date?), I don't know how you want to handle this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2016 18:56:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculating-duration-between-two-times-over-different-dates/m-p/1255573#M870396</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2016-12-02T18:56:36Z</dc:date>
    </item>
  </channel>
</rss>

