This module truncates a datetime object to the level of precision that you specify, making everything higher than that zero (or one for day and month).
It is based on PostgreSQL’s DATE_TRUNC.
Documentation available on Read the Docs.
Installation:
You can install from pypi!
pip install datetime_truncate
Usage:
>>> from datetime_truncate import truncate
>>> truncate(datetime(2012, 2, 4, 12, 24, 50, 234), 'second')
datetime(2012, 2, 4, 12, 24, 50)
>>> truncate(datetime(2012, 2, 4, 12, 24, 50), 'minute')
datetime(2012, 2, 4, 12, 24)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'hour')
datetime(2012, 2, 4, 12)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'day')
datetime(2012, 2, 4)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'week')
datetime(2012, 1, 30)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'month')
datetime(2012, 2, 1)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'quarter')
datetime(2012, 1, 1)
>>> truncate(datetime(2012, 8, 18, 12, 25), 'half_year')
datetime(2012, 7, 1)
>>> truncate(datetime(2012, 8, 18, 12, 25), 'year')
datetime(2012, 1, 1)
There are also sugar functions available on the form:
truncate_second
truncate_minute
truncate_hour
truncate_day
truncate_week
truncate_month
truncate_quarter
truncate_half_year
truncate_year
Metadata
Release files for datetime-truncate 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| datetime_truncate-1.1.1.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| datetime_truncate-1.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 7.1 kB
Release files / datetime_truncate-1.1.1.tar.gz
| Download URL | datetime_truncate-1.1.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00210b54f63f23054c5110801baf53a941df10e3e845e7b8239ccf399bd1e064
|
|
BLAKE2b-256 checksum How to use checksums |
5a72e35570ed6670394c37df67626bfd185c2a9a74253a5bba6b336255b2e6e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3
|
Release files / datetime_truncate-1.1.1-py2.py3-none-any.whl
| Download URL | datetime_truncate-1.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
aa8cafd313caeb2c4614018e9096f82c98fa7dd87635148f51118aecc25965aa
|
|
BLAKE2b-256 checksum How to use checksums |
e9a99680cdffff239bda85f2c0fb384fa6f22741de153c4d0fd158e586baca99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3
|