A tiny, dependency-free Go package that formats time.Time using MySQL DATE_FORMAT()-style tokens (i.e., strftime-like), instead of Go’s layout-string approach.
This is handy if you (or your brain / codebase / DB) already “speaks” MySQL date formats like:
%Y-%m-%d %H:%i:%s
go get github.com/tominkoltd/go-datetime"// Example
s := dateTime.Format(time.Now(), "%W, %D %M %Y %T")
// e.g. "Wednesday, 17th December 2025 20:46:09"| Token | Meaning | Example |
|---|---|---|
%a |
Abbreviated weekday name | Mon |
%W |
Weekday name | Monday |
%w |
Day of week (0=Sunday..6=Saturday) | 0 |
%b |
Abbreviated month name | Dec |
%M |
Month name | December |
%c |
Month (1..12) | 12 |
%m |
Month, 2-digit (01..12) | 12 |
%d |
Day of month, 2-digit (01..31) | 07 |
%e |
Day of month (1..31) | 7 |
%D |
Day of month with suffix | 7th |
%Y |
Year, 4-digit | 2025 |
%y |
Year, 2-digit | 25 |
%H |
Hour, 2-digit (00..23) | 20 |
%k |
Hour (0..23) | 20 |
%h |
%I |
Hour, 12-hour, 2-digit (01..12) |
%l |
Hour, 12-hour (1..12) | 8 |
%p |
AM/PM | PM |
%s |
%S |
Seconds, 2-digit (00..59) |
%T |
Time, 24-hour (HH:MM:SS) |
20:46:09 |
%r |
Time, 12-hour (HH:MM:SS AM/PM) |
08:46:09 PM |
%j |
Day of year (001..366) | 351 |
%U |
Week number, Sunday-start (00..53) | 51 |
%u |
Week number, Monday-start (00..53) | 51 |
%F |
Milliseconds (000..999) | 123 |
%f |
Microseconds (000000..999999) | 123456 |
%% |
Literal percent | % |
Anything unknown after % is treated as a literal character.
Go’s time.Format() is great once memorized, but it’s not token-based. If you’re already dealing with MySQL formats (or just want strftime-style tokens), this package keeps things simple and familiar.
MIT.