# timeGroup function group data on Thursday

**URL:** <https://community.grafana.com/t/timegroup-function-group-data-on-thursday/32750>\
**Category:** Grafana\
**Created:** [June 26, 2020, 10:09am UTC](https://community.grafana.com/t/timegroup-function-group-data-on-thursday/32750 "2020-06-26T10:09:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jerimiahmack](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jerimiahmack](https://community.grafana.com/u/jerimiahmack)\
**Post date:** [March 25, 2021, 7:14pm UTC](https://community.grafana.com/t/timegroup-function-group-data-on-thursday/32750/3 "2021-03-25T19:14:37Z")

</div>

It is because of the way that the $\_\_timeGroup() function calculates bins of 7 days. In the case of MS SQL Server, it applies the following:  
FLOOR(DATEDIFF(second, ‘1970-01-01’, \<time\_column\>)/604800)\*604800

1970-01-01 is considered “0”. It also happened to be a Thursday. 604800 is the number of seconds in a week (60 x 60 x 24 x 7).

The DATEDIFF()/604800 portion calculates the number of elapsed weeks, including partial week, since 1970-01-01, with second precision.  
The FLOOR part drops any fractional week from weeks elapsed, then calculates the number of seconds corresponding to the number of **whole** weeks elapsed, which returns a ‘7-day bin starting on a Thursday’.

$\_\_timeGroup() really should allow a referential offset, but doesn’t.

Rather than using $\_\_timeGroup() you may wish to affect you own FLOOR logic based upon 1970-01-01 + Xday offset to reset your “0” point to the following desired start day. For example: 1970-01-04 (Sunday) or 1970-01-05 (Monday).  
You could use a dashboard variable to map multiple bin widths (hour (3600sec), day (86400sec), week (604800sec), month, etc.) to allow for quick precision changes.

---

_[View the full topic](https://community.grafana.com/t/timegroup-function-group-data-on-thursday/32750)._
