# Group by date and only show posts that are greater than today

**URL:** <https://discourse.gohugo.io/t/group-by-date-and-only-show-posts-that-are-greater-than-today/102>\
**Category:** support\
**Created:** [September 23, 2014, 10:10pm UTC](https://discourse.gohugo.io/t/group-by-date-and-only-show-posts-that-are-greater-than-today/102 "2014-09-23T22:10:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![defpunk](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@defpunk](https://discourse.gohugo.io/u/defpunk)\
**Post date:** [September 23, 2014, 10:10pm UTC](https://discourse.gohugo.io/t/group-by-date-and-only-show-posts-that-are-greater-than-today/102/1 "2014-09-23T22:10:24Z")

</div>

Alongside posts I’m trying to build an events section on my hugo site, so far creating the events has gone well but now I’m trying to both group the events by day and filter them for those after today. So far I’ve only been able to either group them using code like this

```
range .Data.Pages.GroupByDate "Monday, 2 January 2006"

```

or else filter them using code like this

```
{{ range .Data.Pages }}
{{ if ge .Date.Unix .Now.Unix }}

```

has anyone got any ideas how I could do both at the same time?

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [September 24, 2014, 3:26pm UTC](https://discourse.gohugo.io/t/group-by-date-and-only-show-posts-that-are-greater-than-today/102/2 "2014-09-24T15:26:04Z")

</div>

We have a where function ([http://gohugo.io/templates/functions/](http://gohugo.io/templates/functions/)) which works well for this purpose, but only works on equality. Seems like it would be good do have a similar function that handled greater than. WhereGreater for example.

---

<div class="post-metadata">

**Author:** ![tatsushid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tatsushid/32/7219_2.png) [@tatsushid](https://discourse.gohugo.io/u/tatsushid)\
**Post date:** [September 24, 2014, 5:09pm UTC](https://discourse.gohugo.io/t/group-by-date-and-only-show-posts-that-are-greater-than-today/102/3 "2014-09-24T17:09:14Z")

</div>

How about using both GroupByDate and ge like below?

```auto
{{ range .Data.Pages.GroupByDate "Monday, 2 January 2006" }}
  {{ $page := index .Pages 0 }}{{/* Each group has at least 1 page */}}
  {{ if ge $page.Date.Unix $page.Now.Unix }}
    <h2>{{ .Key }}</h2>
    <ul>
      {{ range .Pages }}
        {{ .Render li }}
      {{ end }}
    </ul>
  {{ end }}
{{ end }}

```

Ordinary, GroupByDate returns sorted pages in descending order, means the newest one comes to the top of the list so you can easily determine whether the group should be displayed by only checking the first page date.

I agree with adding a new function which is similar to “where” but can handle other operation or it may be good “where” supports an operator argument like `{{ where .Pages "Section" "=" "post" }}`

---

<div class="post-metadata">

**Author:** ![defpunk](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@defpunk](https://discourse.gohugo.io/u/defpunk)\
**Post date:** [September 25, 2014, 6:37pm UTC](https://discourse.gohugo.io/t/group-by-date-and-only-show-posts-that-are-greater-than-today/102/4 "2014-09-25T18:37:00Z")

</div>

@tatsushid Thanks very much. Your suggested tweak has worked perfectly.
