golang time.Time型とMariaDBの時間型columnのdb.Queryでの比較

1.golang time.Time型とMariaDBの時間型columnのdb.Queryでの比較
MariaDBの時間型column側をDATE関数で変換し、golang time.Time型と比較

2.条件、tableのcolumnの型は時間
下のcodeのlogin_time は TIMESTAMP型、NOT NULL

3.code

t := time.Now()
year := t.Year()
month:= int(t.Month())

start := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
end := time.Date(year, time.Month(month+1), 1, 0, 0, 0, 0, time.Local)

SQL := `
 SELECT
 session_no AS login_id,
 login_time AS login_time,
FROM
 log_session
WHERE
  DATE(login_time) >= ?
AND
  DATE(login_time) < ?
`;

s := bytes.NewBufferString("");
s.WriteString(SQL);

rows, err := db.Query(s.String(),start, end);