Skip to main content

Custom Django ORM expressions for datetime operations.

Project description

django-datetime-expressions

django-datetime-expressions provides custom expressions for Django ORM to simplify datetime operations. It allows relative additions and subtractions to datetime fields.

日本語版 (Japanese Version)

Features

  • Perform relative operations on datetime fields (e.g., add/subtract days, weeks, months, years)
  • Supports multiple database engines (MySQL, SQLite, Oracle)
  • Extract epoch time using EXTRACT

Installation

pip install django-datetime-expressions

Usage

Below is an example of using RelativeDay to manipulate dates.

from datetime import datetime
from django.db.models import F
from datetime_expressions import RelativeDay

# Example: Add 5 days to the current date
queryset = MyModel.objects.annotate(new_date=RelativeDay(F('date_field'), 5))

Supported Relative Operations

Class Name Description Unit
RelativeDay Add/Subtract days Days
RelativeWeek Add/Subtract weeks 7-day units
RelativeMonth Add/Subtract months Months
RelativeYear Add/Subtract years Years
RelativeHour Add/Subtract hours Hours
RelativeMinute Add/Subtract minutes Minutes
RelativeSecond Add/Subtract seconds Seconds

Extracting Epoch Time

Use the Epoch class to extract epoch time (seconds since January 1, 1970) from a datetime field.

from datetime_expressions import Epoch

queryset = MyModel.objects.annotate(epoch_time=Epoch(F('date_field')))

Supported Databases

  • MySQL
  • SQLite
  • Oracle

Contribution

Bug reports and feature requests are welcome on GitHub Issues. Pull requests are also appreciated!

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

django_datetime_expressions-0.2.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_datetime_expressions-0.2.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file django_datetime_expressions-0.2.0.tar.gz.

File metadata

File hashes

Hashes for django_datetime_expressions-0.2.0.tar.gz
Algorithm Hash digest
SHA256 26834284897f24470468e73c2f0a0205303adf13525acfafbced5350e24b41ac
MD5 14e73d3cc588410f70c22f5739403a87
BLAKE2b-256 748e1616372ab0227359c15fdb250eb579121b7c52c22955e5263e7e683ef207

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_datetime_expressions-0.2.0.tar.gz:

Publisher: workflow.yml on towan912/django-datetime-expressions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_datetime_expressions-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_datetime_expressions-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a89bd84993061ce65473906b4dc1dfe6f14f29167060a64f912157158da2231
MD5 80a2dcf077ca51a94faf10b7fd9a8891
BLAKE2b-256 376598fe5566e256de7fa6fcac64ad79c15350b3686341e382b4b2eeb6c0d759

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_datetime_expressions-0.2.0-py3-none-any.whl:

Publisher: workflow.yml on towan912/django-datetime-expressions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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