Filter pages by day

I have some content of type talk that have a .Date parameter. I would like to filter these talk by a particular day (not now). Right now, I only succeed to do it using quite an ugly trick:

{{ $day := "2020-10-01"}}
{{ $tomorrow := .Date.AddDate 0 0 1}}
{{ $query := where $.Site.RegularPages "Type" "talk" }}
{{/* home made filter by day */}}
{{ $query = where $query "Date" "gt" $day }}
{{ $query = where $query "Date" "lt" $tomorrow }}

I suspect that there is a better way to do it, but this did succeed to format the Date parameter into YYY-MM-DD for the “queried” data. This did not work for example ($query is empty)

{{ $day := "2020-10-01"}}
{{ $query := where $.Site.RegularPages "Type" "talk" }}
{{ $query = where $query "(time .Date).Format '2006-01-02'" $day }}

I tried multiple stuff, but neither of which worked (except my “ugly” trick). If there is a better way, I would be happy to know it!

Thanks

The above wouldn’t work. Try using the GroupByDate method.

1 Like

Thank you very much, I don’t know how but I did not see this function!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.