<?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>article Time Difference or Time in Human Readable Format in Member Articles</title>
    <link>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/ta-p/1485105</link>
    <description>&lt;P&gt;How can we represent the time difference between two dates (such as StartDate and EndDate) in a 'human-readable' format, like '1 Day, 18 Hours, 19 Minutes, 36 Seconds'?&lt;/P&gt;
&lt;P&gt;The first step is to convert the time difference into seconds, making it easier to translate into a human-readable format. However, the data format may vary depending on business rules. For example, you might have TimeStart and TimeEnd columns in your data source, requiring you to calculate the time difference, or you might have the time difference pre-calculated in seconds, hours, or minutes. In some cases, the time difference might be stored in hh:mm&lt;BR /&gt;format in the data source.&lt;/P&gt;
&lt;P&gt;Let's demonstrate each scenario&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;1) Case when you have TimeStart and TimeEnd Columns in data source.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;We will convert the time difference into seconds, making it easier to translate the seconds into a human-readable format&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;floor((TimeEnd-TimeStart)*24*60*60) &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;Note: The difference between two timestamps will always be expressed in days, even if you apply the Interval function, as the Interval function is merely a formatting tool&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Below is the complete script for converting the time difference into a human-readable format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Timestamp:
LOAD *,
    if(Years&amp;gt;0,Years &amp;amp; ' Year, ','') &amp;amp;
    if(Months&amp;gt;0,Months &amp;amp; ' Month, ','') &amp;amp;
    if(Days&amp;gt;0,Days &amp;amp; ' Day, ','') &amp;amp;
    if(Hours&amp;gt;0,Hours &amp;amp; ' Hour, ','') &amp;amp;
    if(Minutes&amp;gt;0,Minutes &amp;amp; ' Minute, ','') &amp;amp;
    if(Seconds&amp;gt;0,Seconds &amp;amp; ' Second') as Time_Diff;

LOAD *,
     floor(TimeInSeconds/31104000)  as  Years,            
     floor(mod(TimeInSeconds,31104000) / 2592000)  as  Months,
     floor(mod(TimeInSeconds,2592000) /86400)  as  Days,
     floor(mod(TimeInSeconds,86400) /3600)  as  Hours,
     floor(mod(TimeInSeconds,3600) /60)  as  Minutes,
     mod(TimeInSeconds,60)  as  Seconds; 
                   
LOAD *,
Interval(TimeEnd-TimeStart,'hh:mm:ss') as Time_hhmmss,
floor((TimeEnd-TimeStart)*24*60*60) as TimeInSeconds;
LOAD * Inline [
TimeStart, TimeEnd
21/03/2016 12:11:34, 22/03/2016 02:34:12
20/03/2016 10:14:34, 22/03/2016 04:34:10
18/03/2016 10:15:34, 22/03/2016 04:40:10
20/03/2016 10:14:30, 20/03/2016 10:34:10
21/03/2016 09:11:20, 21/03/2016 09:11:50
21/01/2016 08:11:20, 24/03/2016 09:20:50
20/04/2014 10:09:20, 21/03/2016 11:20:50 ];&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;IMG style="max-width: 1200px; max-height: 900px;" class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/119487_pastedImage_106.png" border="0" alt="" /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;2) Case when you have a time difference pre-calculated as a Second or as a Hour or as a Minute&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If the time difference is expressed in seconds, no conversion is necessary; you can follow the steps in Case 1.&lt;/P&gt;
&lt;P&gt;If the time difference is in hours, multiply the value by 60 * 60 to convert it to seconds, and then follow the steps in Case 1.&lt;/P&gt;
&lt;P&gt;If the time difference is in minutes, multiply the value by 60 to convert it to seconds, and then follow the steps in Case 1.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;3) Case when you have a time difference presented as hh:mm:ss format.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Below is the script to convert the time difference from hh:mm&lt;BR /&gt;to seconds. You can then follow the steps in Case 1 to convert it into a human-readable for&lt;STRONG&gt;&lt;EM&gt;mat.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Time:
LOAD *,
     rangesum(SubField(Time,':',1)*60*60 ,subField(Time,':',2)*60 ,subField(Time,':',3)) as TimeInSeconds 
Inline [
Time
2923:55:57
389:45:43
889:05:36 ];&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="max-width: 1200px; max-height: 900px;" class="jive-image image-4" src="https://community.qlik.com/legacyfs/online/119488_pastedImage_110.png" border="0" alt="" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please feel free to offer any suggestions to improve this document.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2024 18:17:06 GMT</pubDate>
    <dc:creator>Kushal_Chawda</dc:creator>
    <dc:date>2024-09-25T18:17:06Z</dc:date>
    <item>
      <title>Time Difference or Time in Human Readable Format</title>
      <link>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/ta-p/1485105</link>
      <description>&lt;P&gt;How can we represent the time difference between two dates (such as StartDate and EndDate) in a 'human-readable' format, like '1 Day, 18 Hours, 19 Minutes, 36 Seconds'?&lt;/P&gt;
&lt;P&gt;The first step is to convert the time difference into seconds, making it easier to translate into a human-readable format. However, the data format may vary depending on business rules. For example, you might have TimeStart and TimeEnd columns in your data source, requiring you to calculate the time difference, or you might have the time difference pre-calculated in seconds, hours, or minutes. In some cases, the time difference might be stored in hh:mm&lt;BR /&gt;format in the data source.&lt;/P&gt;
&lt;P&gt;Let's demonstrate each scenario&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;1) Case when you have TimeStart and TimeEnd Columns in data source.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;We will convert the time difference into seconds, making it easier to translate the seconds into a human-readable format&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;floor((TimeEnd-TimeStart)*24*60*60) &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;Note: The difference between two timestamps will always be expressed in days, even if you apply the Interval function, as the Interval function is merely a formatting tool&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Below is the complete script for converting the time difference into a human-readable format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Timestamp:
LOAD *,
    if(Years&amp;gt;0,Years &amp;amp; ' Year, ','') &amp;amp;
    if(Months&amp;gt;0,Months &amp;amp; ' Month, ','') &amp;amp;
    if(Days&amp;gt;0,Days &amp;amp; ' Day, ','') &amp;amp;
    if(Hours&amp;gt;0,Hours &amp;amp; ' Hour, ','') &amp;amp;
    if(Minutes&amp;gt;0,Minutes &amp;amp; ' Minute, ','') &amp;amp;
    if(Seconds&amp;gt;0,Seconds &amp;amp; ' Second') as Time_Diff;

LOAD *,
     floor(TimeInSeconds/31104000)  as  Years,            
     floor(mod(TimeInSeconds,31104000) / 2592000)  as  Months,
     floor(mod(TimeInSeconds,2592000) /86400)  as  Days,
     floor(mod(TimeInSeconds,86400) /3600)  as  Hours,
     floor(mod(TimeInSeconds,3600) /60)  as  Minutes,
     mod(TimeInSeconds,60)  as  Seconds; 
                   
LOAD *,
Interval(TimeEnd-TimeStart,'hh:mm:ss') as Time_hhmmss,
floor((TimeEnd-TimeStart)*24*60*60) as TimeInSeconds;
LOAD * Inline [
TimeStart, TimeEnd
21/03/2016 12:11:34, 22/03/2016 02:34:12
20/03/2016 10:14:34, 22/03/2016 04:34:10
18/03/2016 10:15:34, 22/03/2016 04:40:10
20/03/2016 10:14:30, 20/03/2016 10:34:10
21/03/2016 09:11:20, 21/03/2016 09:11:50
21/01/2016 08:11:20, 24/03/2016 09:20:50
20/04/2014 10:09:20, 21/03/2016 11:20:50 ];&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;IMG style="max-width: 1200px; max-height: 900px;" class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/119487_pastedImage_106.png" border="0" alt="" /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;2) Case when you have a time difference pre-calculated as a Second or as a Hour or as a Minute&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If the time difference is expressed in seconds, no conversion is necessary; you can follow the steps in Case 1.&lt;/P&gt;
&lt;P&gt;If the time difference is in hours, multiply the value by 60 * 60 to convert it to seconds, and then follow the steps in Case 1.&lt;/P&gt;
&lt;P&gt;If the time difference is in minutes, multiply the value by 60 to convert it to seconds, and then follow the steps in Case 1.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;3) Case when you have a time difference presented as hh:mm:ss format.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Below is the script to convert the time difference from hh:mm&lt;BR /&gt;to seconds. You can then follow the steps in Case 1 to convert it into a human-readable for&lt;STRONG&gt;&lt;EM&gt;mat.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Time:
LOAD *,
     rangesum(SubField(Time,':',1)*60*60 ,subField(Time,':',2)*60 ,subField(Time,':',3)) as TimeInSeconds 
Inline [
Time
2923:55:57
389:45:43
889:05:36 ];&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="max-width: 1200px; max-height: 900px;" class="jive-image image-4" src="https://community.qlik.com/legacyfs/online/119488_pastedImage_110.png" border="0" alt="" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please feel free to offer any suggestions to improve this document.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 18:17:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/ta-p/1485105</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-09-25T18:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference or Time in Human Readable Format</title>
      <link>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/tac-p/1485106#M1438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good job &lt;SPAN style="color: #8b8b8b; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12px;"&gt; &lt;/SPAN&gt;&lt;A href="https://community.qlik.com/people/Kush141087"&gt;Kush141087&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sharing&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 10:29:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/tac-p/1485106#M1438</guid>
      <dc:creator>Joaquin_Lazaro</dc:creator>
      <dc:date>2016-03-29T10:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference or Time in Human Readable Format</title>
      <link>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/tac-p/1485107#M1439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good One. Thank you for Sharing..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 11:44:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/tac-p/1485107#M1439</guid>
      <dc:creator>settu_periasamy</dc:creator>
      <dc:date>2016-03-29T11:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference or Time in Human Readable Format</title>
      <link>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/tac-p/1485108#M1440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice thought.. Thank you for sharing..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Mar 2016 05:23:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Time-Difference-or-Time-in-Human-Readable-Format/tac-p/1485108#M1440</guid>
      <dc:creator>psankepalli</dc:creator>
      <dc:date>2016-03-30T05:23:17Z</dc:date>
    </item>
  </channel>
</rss>

