# Displaying time on a widget

**URL:** <https://community.holistics.io/t/displaying-time-on-a-widget/1394>\
**Category:** Ask the Community\
**Tags:** data-format, visualizations\
**Created:** [January 29, 2023, 11:04am UTC](https://community.holistics.io/t/displaying-time-on-a-widget/1394 "2023-01-29T11:04:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Weisblatt](https://community.holistics.io/user_avatar/community.holistics.io/ben_weisblatt/32/1036_2.png) [@Ben\_Weisblatt](https://community.holistics.io/u/Ben_Weisblatt)\
**Post date:** [January 29, 2023, 11:04am UTC](https://community.holistics.io/t/displaying-time-on-a-widget/1394/1 "2023-01-29T11:04:19Z")

</div>

Two questions regarding displaying time on Holistics platform.  
I have a TIME column in a MySQL DB - The time is when an event started.  
I want to show an average of when it started every day for the past X months.  
So if half the time it started at 8:00AM and half at 9:AM the Average will show 8:30AM.

Second question is regarding activity time. I have the total amount of minutes that occurred in a day. But I don’t want to display 489 minutes. And I don’t want to arbitrarily divide that into 60 and show 8.15 hours.  
I’d rather show it in a TIME format, in this case it would be 8:09 hours.

Can someone help me with these issues?

Thank you!

---

<div class="post-metadata">

**Author:** ![triet.pham](https://community.holistics.io/user_avatar/community.holistics.io/triet.pham/32/10_2.png) [@triet.pham](https://community.holistics.io/u/triet.pham)\
**Post date:** [January 30, 2023, 9:21am UTC](https://community.holistics.io/t/displaying-time-on-a-widget/1394/2 "2023-01-30T09:21:26Z")

</div>

Hi Ben,

Thank you for posting your questions.

I’m answering your **2nd question** first: Showing the total amount of minutes in a TIME format.

This can be achieved by adding a [Custom Dimension](https://docs.holistics.io/docs/model-fields#adding-custom-dimensions-to-data-model) to your model.  
For example, I have a column called `minute_count_col`

 ![image](https://community.holistics.io/uploads/default/original/2X/d/d709586445e63c0fcf0a6c236dbe31e054674726.png)

and I added a Custom Dimension like this

 ![image](https://community.holistics.io/uploads/default/original/2X/a/a5f628e488a8081306fc206830e47a5456ffb034.png)

The SQL query above `CONCAT(FLOOR({{ #THIS.minute_count_col }}/60),':',LPAD(MOD({{ #THIS.minute_count_col }},60),2,'0'))`

Here is what it looks like in the report

 ![image](https://community.holistics.io/uploads/default/original/2X/c/ceafd553a032a24546a068e98befe73490f3923a.png)

You can modify the SQL query to get your desired output format.

---

<div class="post-metadata">

**Author:** ![triet.pham](https://community.holistics.io/user_avatar/community.holistics.io/triet.pham/32/10_2.png) [@triet.pham](https://community.holistics.io/u/triet.pham)\
**Post date:** [January 30, 2023, 9:51am UTC](https://community.holistics.io/t/displaying-time-on-a-widget/1394/3 "2023-01-30T09:51:52Z")

</div>

Regarding your first question

> I want to show an average of when it started every day for the past X months.  
> So if half the time it started at 8:00AM and half at 9:AM the Average will show 8:30AM.

I’m not sure how will you want to show this value on your report and Holistics also does not natively support the type TIME column, so the easiest way I think is to convert the TIME column to minutes → Calculate the average minutes → Convert it back to type TIME or format the same as above (question 2nd)  
Ref: [https://stackoverflow.com/a/2217195/1819549](https://stackoverflow.com/a/2217195/1819549)

For aggregating value, the [Custom Measure](https://docs.holistics.io/docs/model-fields#how-to-convert-a-sql-statement-to-a-custom-measure) can help in your case. The query would be like this (I copy from the doc and modify a bit)

```sql
SEC_TO_TIME(AVG(
  CASE {{ #THIS.created_at }} BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
  WHEN TRUE THEN TIME_TO_SEC({{ #THIS.time_col }})
  ELSE NULL
 END
)) 

```

Here is what it looks like (Disclaimer: I haven’t checked whether it’s showing correctly or not as I’m playing around with randomized data, but it _looks_ right, haha)

 ![image](https://community.holistics.io/uploads/default/original/2X/d/d92387d63f6b8e067549d74ecf8d33695d6c4a4f.png)

Btw, if it’s not what are you looking for, maybe you can check [Transform Models](https://docs.holistics.io/docs/transform-models) as it allows you to create a data model from a SQL query which you can manipulate the however you want.
