Skip to content

A small, dependency-free Go package that provides strftime-like date/time formatting, without using Go’s layout-string quirks.

Notifications You must be signed in to change notification settings

tominkoltd/go-datetime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dateTime

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

Install

go get github.com/tominkoltd/go-datetime"

Usage

// Example
s := dateTime.Format(time.Now(), "%W, %D %M %Y %T")
// e.g. "Wednesday, 17th December 2025 20:46:09"

Supported tokens (MySQL-style)

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.


Why not Go layouts?

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.


License

MIT.

About

A small, dependency-free Go package that provides strftime-like date/time formatting, without using Go’s layout-string quirks.

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages