The Django AddSeconds package provides a number of useful Django template filters for datetime manipulations.
Stable version from the PyPi package repository
pip install django-addseconds
Last development version from the GitHub source version control system
pip install git+git://github.com/nnseva/django-addseconds.git
Include the addseconds
application into the INSTALLED_APPS
list, like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'addseconds',
...
]
Load the library into your template:
{% load addseconds %}
Use provided template filters as described in the Django documentation.
Adds passed number of seconds to the datetime value, for example:
{% load addseconds %}
{{ value|addseconds:3600 }}
Notice that the value
passed to the template may be datetime
value, date
value, float
, int
, or str
,
all of them are converted to the datetime
. The date
value is converted to the datetime
at midnight.
The float
or int
value is converted as a unixtime. The str
value is converted using
django.utils.dateparse.parse_datetime
call.
Notice that the template filter argument may be float
as well as int
.
Calls django.utils.dateparse.parse_datetime
{% load addseconds %}
{{ "2011-11-01 12:13"|parse_datetime }}
Calls django.utils.dateparse.parse_date
{% load addseconds %}
{{ "2011-11-01"|parse_date }}
Calls django.utils.dateparse.parse_time
{% load addseconds %}
{{ "12:13"|parse_time }}