Reputation: 1
I'm trying to extract a date from an excel spreadsheet, I managed to give a log where it shows the entire date, I wanted to know how to extract only the month, for example, in this case it's "log.Println("DT REFER", emp. DT_REFER" the DT_REFER is where the date is in the spreadsheet, how can I get only the month out of it? the format that came was this. DT REFER 2011-03-31
Upvotes: 0
Views: 370
Reputation: 462
You can use fmt.Sscanf
to extract the month out of the log string that you have. Given you have a fixed string structure that you can match against as follows:
// if emp.DT_REFER isn't string use Sprint to make it string
s := fmt.Sprint(emp.DT_REFER)
y, m, d := 0, 0, 0
fmt.Sscanf(s, "%d-%d-%d", &y, &m, &d)
fmt.Println(y, m, d)
Upvotes: 1