groupBy sub string?

I am fetching a collection of pages and grouping them based on the date they have. I would like to group by just YYYY-MM in order to get a group for each month containing pages. Is it possible to groupBy a substr of a field?

$groups = $site->page(‘press’)->children()->visible()->sortBy(‘date’, ‘desc’)->groupBy(‘date’);

Not using groupBy() but you can use group() with a callback.

Perfect this works great, thanks!