I'm new programming by Golang and Databases and I'm doing a filter where I have a Row "created_at" in format "YYYY-MM-DD HH:MM:SS" and I want to select just from a year, here is the line what I have:
func SelectedYear(database string) (consult []models.Consult, err error) {
connection, err := Connection.ConnectToDatabase(database)
if err != nil {
return nil, err
}
connection.Preload("Doctors").Preload("Patients").Preload("Payments").Where("created_at", ">", "2020-00-00 00:00:00").Where("created_at", ">", "2021-00-00 00:00:00").Find(&consult)
return consult, nil
}
"Doctors", "Patients" and "Payments" are part from a Foreign key, that's why I use "Preload".
This is an example how I want to make it explained with C++
if (created_at > 2020 && created_at < 2021){
}
and... if someone could help me too to find how to make the filter by name from "Patients" and "Doctors" I'll be very grateful :)