Your Question

I'm trying to use the Count finisher in order to get the amount of rows by day. The problem is that the column with the date contains timestamp information, and I want it grouped by day.

I managed to do it using to_char on Postgres and strftime on SQLite, however I'd like to know if there's a way to do it better.

// postgres
      db.Model(&model.DeviceTransaction{}).
        Where("created_at = ?", startDate).
        Group("to_char(created_at, 'YYYY-MM-DD')").
        Count(&count).

// sqlite
      db.Model(&model.DeviceTransaction{}).
        Where("created_at = ? ", startDate).
        Group("strftime('%Y-%m-%d',created_at)").
        Count(&count).  

The document you expected this should be explained

https://gorm.io/docs/advanced_query.html#Count

Expected answer

It'd be nice if there's a way to format group by fields generically.

Comment From: LeandroFranciscato

answered in https://github.com/go-gorm/gorm/pull/5777#issuecomment-1281975634