TryBugHunt
goOtherEasy

Time format layout error using standard date

BugFind the bug and fix the code

What it should do

Format time using year-month-day layout. Example: formatCustomDate(2026, 11, 9) -> "2026-11-09"

What happens instead

Output string produces corrupted date format like YYYY-MM-DD

package main

import (
	"fmt"
	"time"
)

func formatCustomDate(year, month, day int) string {
	t := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
	// Go does not use YYYY-MM-DD; it uses reference time 2006-01-02
	return t.Format("YYYY-MM-DD")
}

func main() {
	fmt.Println(formatCustomDate(2026, 11, 9))
}

Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).

⏱️0:00
Hints
🏆 0 hints = Flawless Solve
Think & Test Cooldown
2:00 remaining

Take a moment to read the bug symptom and trace the code with Run & Check before unlocking Hint 1.

Hint 2
Unlocks after Hint 1
Hint 3
Unlocks after Hint 2

This bug belongs to the mutation and copying bugs pattern

Slices that share one backing array, so changing a copy changes the original.

What you'll practise

An easy Go debugging exercise about mutation and copying bugs: slices that share one backing array, so changing a copy changes the original.

The checks your fix must pass

Signs of this kind of bug

Spoiler: why this bug happens(try it first; the hints get warmer one at a time)

What went wrong: Go does not use format specifiers like YYYY-MM-DD. Instead, time.Format uses a specific reference date: Jan 2 15:04:05 2006 MST (1 2 3 4 5 6).

The fix: Use the Go reference format string "2006-01-02".

Remember: Go's time layout string is always based on the reference time: 2006 for year, 01 for month, 02 for day.

The pattern behind it: mutation and copying bugs.

More mutation and copying bugs to practise

Embed this challenge on your site

Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.

<iframe src="https://trybughunt.com/embed/aba39d42-3284-4082-997a-721e6192a696" title="Debugging challenge: Time format layout error using standard date" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/aba39d42-3284-4082-997a-721e6192a696">TryBugHunt</a></p>