Technical notes on web development, DevOps, and AI integration.
1 article
time.Truncate cuts by duration since the zero time, not to local midnight. Here is the safe pattern for DATE columns.
TL;DR: Go's time.Truncate(24 * time.Hour) counts multiples from Go's zero time, not local midnight, so early-morning timestamps on a UTC+7 server slip to the previous day. The MySQL driver's default UTC location conversion then locks the wrong day in. Fix: extract date components and rebuild with time.Date at UTC midnight.