Fetching NULL datetime value in MySQL using GORM
You can set OutTime as a pointer so that it could be null. As seen in the doc:
type YourStruct struct {
OutTime *time.Time
}
Then run your query
db.Where("out_time = ?", nil).Last(&visitDetail)
Go doesn't recognize NULL in particular. I think you can achieve it using a raw query in GORM. like this.
db.Raw("SELECT * FROM visit_details WHERE out_time is NULL order by id desc limit 1").Scan(&visitDetail)
This is one one to fetch the column. Hope this helps.
Just specify IS NULL
in the query without the wildcard.
db.Where("out_time IS NULL").Last(&visitDetail)