I have below code. Having date value as string type from request and trying to convert to time type. But, I have some issue with format.
type LeanData struct {
Start_Date time.Time
}
const dateLayout = "01-02-2006"
startdate := request.FormValue("startdate")
if len(strings.TrimSpace(startdate)) > 0 {
sdate, err := time.Parse(dateLayout, startdate)
}
fmt.Println("startdate", startdate)
fmt.Println("sdate", sdate)
I have below output.
startdate 02-03-2016
sdate 2016-02-03 00:00:00 +0000 UTC
Here, I am doing conversion because start date is of type time.Time. I want to convert it as 2016-02-03 but not with 2016-02-03 00:00:00 +0000 UTC. Also, How to assign empty value to start date if value from request is nil/empty.
Can someone let me know how to achieve this?