Convert Month Year into the Time format?


How can I convert Parse Month and Year to Time?

For Example: I have Month and Year field which are in int format, so I converted that to string format using
MonthString : = Strconv.Itoa(Month) YearString := Strconv.Itoa(Year)

Now I am trying to convert MonthString, and YearString to time Format but I am getting no result when I use time.Parse function.

I am using time.Parse("012006",monthString + YearString) but in return I am getting 010001

Can someone plz help me to resolve this issue?

Hi, @Yo_94, If you already have the month and year as integers, why not just create a new time.Time out of it with the time.Date function?

t := time.Date(Year, Month, 1, 0, 0, 0, 0, nil)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.