GORM Playground Link
https://github.com/go-gorm/gorm/tree/v1.25.3
Description
表结构
CREATE TABLE `user1` (
`uid` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
`create_date` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
`num` int NOT NULL DEFAULT '0',
PRIMARY KEY (`uid`,`create_date`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin;
伪造数据
INSERT INTO `test`.`user1` (`uid`, `create_date`, `num`) VALUES ('zzz', '2023-08-18', 1);
查询
m := map[string]interface{}{}
db.Table("user1").Where("create_date=?", time.Unix(1692288000, 0)).Take(&m)
fmt.Println(m)
日志中打印出来的sql
[0.332ms] [rows:1] SELECT * FROM `user1` WHERE create_date='2023-08-18 00:00:00' LIMIT 1
实际执行的sql
SELECT * FROM `user1` WHERE create_date='2023-08-18' LIMIT 1
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: LYQlemon
I think you can solve your problem by adding .Format("2006-04-02") after the time.Unix method
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨