Skip to main content

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_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

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

datetime_truncate-1.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

datetime_truncate-1.1.1-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file datetime_truncate-1.1.1.tar.gz.

File metadata

  • Download URL: datetime_truncate-1.1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for datetime_truncate-1.1.1.tar.gz
Algorithm Hash digest
SHA256 00210b54f63f23054c5110801baf53a941df10e3e845e7b8239ccf399bd1e064
MD5 897a34c7b29a835e97901ba3ae4df30f
BLAKE2b-256 5a72e35570ed6670394c37df67626bfd185c2a9a74253a5bba6b336255b2e6e5

See more details on using hashes here.

File details

Details for the file datetime_truncate-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: datetime_truncate-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for datetime_truncate-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aa8cafd313caeb2c4614018e9096f82c98fa7dd87635148f51118aecc25965aa
MD5 a6604098784cf7a0c2cc948fdd7bcf61
BLAKE2b-256 e9a99680cdffff239bda85f2c0fb384fa6f22741de153c4d0fd158e586baca99

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page