Recently, I've had been trying to find a way to know if a given date is greater or equal than today. The GitHub Copilot has suggested I should use the following algorithm:
date := "2021-01-01"
today := time.Now().Format("2006-01-02")
switch {
case date == today:
fmt.Println("Equal")
case date < today:
fmt.Println("Less")
case date > today:
fmt.Println("Greater")
}
// Less
So, I've tried with some testing dates and, the result is always correct. However, I'd like to know whether if this is a good way to make date comparisons or it may lead to a wrong response at any moment?
Thank you in advance.