<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to split in DD HH MM SS from hours more then 24 hours]]></title><description><![CDATA[<p dir="auto">Hello everybody,<br />
with a mysql query I extract the sum of the hours of a work process  and I want to display them in the format DD HH: MM: SS<br />
I am using this code which works fine within 24 hours.<br />
But for all processing beyond 24 QTime it fails</p>
<pre><code>QString query = QString("SELECT TIME(SUM(SEC_TO_TIME(time_work))) FROM works WHERE id_work = 1 GROUP BY(id_employee) ORDER BY id_work ASC");
  QSqlQuery query_time;
  query_time.prepare(query);

  if (query_time.exec())
    {
      while (query_time.next())
        {
          sec_work = sec_work + QTime(0, 0, 0).secsTo(query_time.value(0).toTime());
        }
      int dd = ?                            // my days (DD)
      int hh = sec_work/3600;               // my hours (HH)
      int mm = (sec_work%3600)/60;          // my minuts (MM)
      int ss = (sec_work%3600)%60;          // my seconds (SS)
    }
</code></pre>
<p dir="auto">How can I find the days (DD) if the hours exceed 24 ?<br />
Thank you in advance</p>
<p dir="auto">blackout69</p>
]]></description><link>https://forum.qt.io/topic/124624/how-to-split-in-dd-hh-mm-ss-from-hours-more-then-24-hours</link><generator>RSS for Node</generator><lastBuildDate>Tue, 19 May 2026 06:57:50 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/124624.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Mar 2021 20:15:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Thu, 11 Mar 2021 14:30:09 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the suggestions.<br />
I solved it like this:</p>
<pre><code>// my query:
QString query = QString("SELECT lastname, date, SUM(time_work) FROM works WHERE id_work = 1 GROUP BY(id_employee) ORDER BY id_work ASC");

// my custom delegate:
void ColCustomTimeDelegato::paint(QPainter *painter, const QStyleOptionViewItem &amp; option, const QModelIndex &amp; index) const
{
  int value = index.model()-&gt;data(index, Qt::DisplayRole).toInt();
  QStyleOptionViewItem myOption = option;
  myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
  drawDisplay(painter, myOption, myOption.rect, QString("%1:%2:%3").arg(value/3600).arg((value%3600)/60).arg((value%3600)%60));
  drawFocus(painter, myOption, myOption.rect);
}
</code></pre>
<p dir="auto">It works very well.<br />
Thanks again.</p>
]]></description><link>https://forum.qt.io/post/649098</link><guid isPermaLink="true">https://forum.qt.io/post/649098</guid><dc:creator><![CDATA[blackout69]]></dc:creator><pubDate>Thu, 11 Mar 2021 14:30:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 23:19:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/blackout69">@<bdi>blackout69</bdi></a> I'd try to supply data as seconds and do the math in the delegate dropping QTime. The only thing to check is if this will be fast enough.</p>
]]></description><link>https://forum.qt.io/post/648963</link><guid isPermaLink="true">https://forum.qt.io/post/648963</guid><dc:creator><![CDATA[artwaw]]></dc:creator><pubDate>Wed, 10 Mar 2021 23:19:48 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 23:15:31 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
for my application, I need to show the processing time on a QTableView.<br />
This is the code that shows the data I extract from the query .</p>
<pre><code>//My delegate...

ColTimeDelegate::ColTimeDelegate(QObject *parent) : QItemDelegate(parent)
{

}

void ColTimeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &amp; option, const QModelIndex &amp; index) const
{
  QTime text = index.model()-&gt;data(index, Qt::DisplayRole).toTime();
  QStyleOptionViewItem myOption = option;
  myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
  drawDisplay(painter, myOption, myOption.rect, text.toString("hh:mm:ss"));
  drawFocus(painter, myOption, myOption.rect);
}

//My application code...

QString query = QString("SELECT lastname, date, TIME(SUM(SEC_TO_TIME(time_work))) FROM works WHERE id_work = 1 GROUP BY(id_employee) ORDER BY id_work ASC");

model = new QSqlQueryModel(this);
model-&gt;setQuery(query);
model-&gt;setHeaderData(0, Qt::Horizontal, tr("Employee"));
model-&gt;setHeaderData(1, Qt::Horizontal, tr("Date"));
model-&gt;setHeaderData(2, Qt::Horizontal, tr("Time"));   // Fail this field. The time is not shown on this field 

// show
ui-&gt;view-&gt;setModel(model);
ui-&gt;view-&gt;resizeColumnsToContents();
ui-&gt;view-&gt;horizontalHeader()-&gt;setStretchLastSection(true);
ui-&gt;view-&gt;setItemDelegateForColumn(1, new ColDataDelegate(this));
ui-&gt;view-&gt;setItemDelegateForColumn(2, new ColTimeDelegate(this));
</code></pre>
<p dir="auto">blackout69</p>
]]></description><link>https://forum.qt.io/post/648962</link><guid isPermaLink="true">https://forum.qt.io/post/648962</guid><dc:creator><![CDATA[blackout69]]></dc:creator><pubDate>Wed, 10 Mar 2021 23:15:31 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 20:40:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Why not just retrieve the sum in your query rather than making it a TIME type ?</p>
]]></description><link>https://forum.qt.io/post/648943</link><guid isPermaLink="true">https://forum.qt.io/post/648943</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 10 Mar 2021 20:40:43 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 20:35:13 GMT]]></title><description><![CDATA[<p dir="auto">sure, but my query returns a value of type TIME and I cannot do operations with QTime if the value exceeds 24 hours. Maybe I should turn it all into seconds and move on. But I don't know which method to use to do this.</p>
]]></description><link>https://forum.qt.io/post/648941</link><guid isPermaLink="true">https://forum.qt.io/post/648941</guid><dc:creator><![CDATA[blackout69]]></dc:creator><pubDate>Wed, 10 Mar 2021 20:35:13 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 20:26:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/blackout69">@<bdi>blackout69</bdi></a> said in <a href="/post/648937">Hot to split in DD HH MM SS from hours more then 24 hours</a>:</p>
<blockquote>
<p dir="auto">35:46:24 in HH: MM: SS and when I pass it to QTime it fails.</p>
</blockquote>
<p dir="auto">As I just wrote above....</p>
]]></description><link>https://forum.qt.io/post/648938</link><guid isPermaLink="true">https://forum.qt.io/post/648938</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 10 Mar 2021 20:26:40 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 20:25:38 GMT]]></title><description><![CDATA[<p dir="auto">Hi Artur,<br />
yes of course this is correct. But my query returns a TIME value for example of 35:46:24 in HH: MM: SS and when I pass it to QTime it fails.</p>
]]></description><link>https://forum.qt.io/post/648937</link><guid isPermaLink="true">https://forum.qt.io/post/648937</guid><dc:creator><![CDATA[blackout69]]></dc:creator><pubDate>Wed, 10 Mar 2021 20:25:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 20:25:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/blackout69">@<bdi>blackout69</bdi></a> said in <a href="/post/648931">Hot to split in DD HH MM SS from hours more then 24 hours</a>:</p>
<blockquote>
<p dir="auto">But for all processing beyond 24 QTime it fails</p>
</blockquote>
<p dir="auto"><code>QTime</code> represents a time-of-day, 0 to 24 hours.  So you will have to deal with your "multiple days" part outside of a <code>QTime</code>.</p>
<p dir="auto">For the rest, as <a class="plugin-mentions-user plugin-mentions-a" href="/user/artwaw">@<bdi>artwaw</bdi></a> says.</p>
]]></description><link>https://forum.qt.io/post/648936</link><guid isPermaLink="true">https://forum.qt.io/post/648936</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 10 Mar 2021 20:25:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to split in DD HH MM SS from hours more then 24 hours on Wed, 10 Mar 2021 20:19:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/blackout69">@<bdi>blackout69</bdi></a> I am not sure if I understood your problem correctly but 24hrs is 86400 seconds. So, to get full days (Assuming no. of seconds is greater than 86400) would lead to  <code>int dd = sec_work/86400;</code></p>
]]></description><link>https://forum.qt.io/post/648933</link><guid isPermaLink="true">https://forum.qt.io/post/648933</guid><dc:creator><![CDATA[artwaw]]></dc:creator><pubDate>Wed, 10 Mar 2021 20:19:13 GMT</pubDate></item></channel></rss>