Truncate datetime objects to a set level of precision
Project description
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_util 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)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file datetime_truncate-1.0.0.tar.gz
.
File metadata
- Download URL: datetime_truncate-1.0.0.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4767500cddb4ae1d48af354c74ffbc9dc05e10a5d0ed02ca3be9df9b272e3397 |
|
MD5 | 3867175cf50ff97c5a20aae81aff8e57 |
|
BLAKE2b-256 | 30c822b19828f5be7d46a59ca3f154d247cd41c2195f435d64905369ed00265e |