0

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

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Feb 28, 2022 at 0:45

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

the problem is that it is getting it from a csv file inside the DT_REFER, I wanted to know how to get only the month out of it
I have updated the answer to consider we need to take out month from DT_REFER itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.