Date formatting in Go is quirky

9 Dec 2023

When I’m working in an unfamiliar language, I find its quicker to just ask ChatGPT to write samples of anything I need than to look it up. For instance, last night I needed to format a date in Go, and rather than Google that and pick one of the results and scroll past the ads to read something, I just asked ChatGPT to give me a code example of formatting a date I gave it to DDMMYYYY.

The answer it spat out, was something like:

dateString := currentTime.Format("02012006")

Well, clearly it was hallucinating - it must have gotten confused between the date I gave it and the formatting string. Odd, but this flavour of things happens. It’s usually pretty good about fixing it if you point out an error, so I did that. It immediately apologised, agreed it had made an error, and gave me back the exact same thing. Poop, I guess it’s back to googling some docs then.

wtf

Well there you go. 1/2 3:04:05pm 2006 - 1-2-3-4-5-6. That’s what’s up with Go time/date formatting. I probably would have thought that was cute when I was 20 something as well.