Compact string-based date(time) format for logging, data engineering, and visualizations.
- Compact: 4 ASCII characters for date, 7 characters for datetime
- URL safe: uses Base62 encoding
- Natural sorting
- Semi-human-readable
- Covers range from 567-Jan-01 to 3843-Dec-31
- Arbitrary sub-second precision
- More readable shortcut form for values between 1970-Jan-01 and 2069-Dec-31
- Timezone info not supported at the moment
- Use cases:
- Logging timestamps
- Visualize dates on charts
- Datetime-based file identifiers
- Sub-second-precision string labels
$ pip install date62
date or datetime | Date62 |
---|---|
2024-Dec-29 | 24CT , WeCT |
2025-Jan-01 | 2511 , Wf11 |
2025-Jan-01 00:01:02 | 2511012 , Wf11012 |
2025-Jan-01 00:01:02.345 | 25110125Z , Wf... |
2025-Jan-01 00:01:02.345678 | 25110125ZAw , Wf... |
2025-Jan-01 00:01:02.345678012 | 25110125ZAw0C , Wf... |
2025-Jan-01 00:01:02.345678012345 | 25110125ZAw0C5Z , Wf... |
Works for datetime
, date
, time
, int
, float
, Decimal
.
>>> from datetime import datetime
>>> from decimal import Decimal
>>> import date62
>>> d = '2024-12-29 12:34:56.789012'
>>> dtm = datetime.strptime(d, '%Y-%m-%d %H:%M:%S.%f')
>>> date62.encode(dtm)
'WeCTCYu'
>>> date62.encode(dtm, scut=True, prec=2)
'24CTCYuCj0C'
>>> date62.encode(dtm.date(), scut=True)
'24CT'
>>> date62.encode(dtm.time())
'CYu'
>>> date62.encode(dtm.time(), prec=3)
'CYuCj0C00'
>>> t = '1735468496.789012345678'
>>> date62.encode(Decimal(t), scut=True, prec=4)
'24CTAYuCj0C5ZAw'
$ python -m date62 --help
usage: date62 [-h] [--version] {encode,now,time,today} ...
options:
-h, --help show this help message and exit
--version show program's version number and exit
subcommands:
{encode,now,time,today}
encode Encode ISO 8601 datetime string to Date62 format.
now Current local datetime in Date62 format.
time Current local datetime in Date62 format.
today Current local date in Date62 format.
$ date62 parse --help
usage: date62 encode [-h] [-n] [-p INT] text
positional arguments:
text text containing date or datetime
options:
-h, --help show this help message and exit
-n, --noscut do not use shortcut form of Date62
-p, --prec INT sub-second precision: 1=milli, 2=micro, 3=nano, etc.
$ date62 now --help
usage: date62 now [-h] [-n] [-p INT]
options:
-h, --help show this help message and exit
-n, --noscut do not use shortcut form of Date62
-p, --prec INT sub-second precision: 1=milli, 2=micro, 3=nano, etc.
$ date62 now --help
usage: date62 time [-h] [-p INT]
options:
-h, --help show this help message and exit
-p, --prec INT sub-second precision: 1=milli, 2=micro, 3=nano, etc.
$ date62 today --help
usage: date62 today [-h] [-n]
options:
-h, --help show this help message and exit
-n, --noscut do not use shortcut form of Date62
Pull requests, feature requests, and bug reports are welcome!
- Michael Makukha