Grouping posts by date?

Hi all,

Has anyone figured out a way to “group” posts by date within a {{foreach}} loop?

Right now I’m presenting my posts sorted by date in descending order, and printing the “published on” date below the title of every post.

What I’d like to do is only print each date once as a “heading,” thereby grouping the posts from the same day together, e.g.:

June 26, 2019

{{post 1 title}}
{{post 1 body}}

{{post 2 title}}
{{post 2 body}}

June 25, 2019

{{post 3 title}}
{{post 3 body}}

June 24, 2019

{{post 4 title}}
{{post 4 body}}

I’ve looked at the “if” “date” and “foreach” portions of the docs, but haven’t been able to figure out a way to encode “only print the date if it is different from the last post” into my theme.

Any suggestions or ideas? Is there another way I should be trying to accomplish this?

Thanks!

Chris