Skip to content

New Jinja filters for date and time manipulations

With this latest rollout, we're introducing a collection of Jinja filters designed to redefine how you approach document generation and sequencing. These new filters provide enhanced functionality, allowing users to manipulate dates and times and perform advanced calculations effortlessly.

Below is a summary of each filter and how it can benefit your workflow.

1. Filter for testing date range

Perfect for checking if a document was created within a specific period or verifying if a task deadline falls within a project timeline.

Syntax: {{ value is in_date_range(start_date, end_date) }}

OperationExampleOutput
Determining if a date falls between two given dates{{ "2024-01-11" is in_date_range("2024-01-10", "2024-01-18") }}True

2. Filter for calculating the number of days between dates

Ideal for determining the duration between two given dates, for example calculating the interval between contract signing and renewal dates.

Syntax: {{ value|delta_days(comparison_date, business_days=False) }}

OperationExampleOutput
Calculating the number of days between dates{{ "2024-04-12"|delta_days("2024-04-13", business_days=False) }}2
Calculating the number of business days between dates{{ "2024-04-12"|delta_days("2024-04-13", business_days=True) }}1

Note: when determining the number of days between dates, the calculation encompasses both the initial and final dates. It's important to note the method employed in calculating business days between dates. In instances where the start and end dates coincide, such as {{ "2024-04-12"|delta_days("2024-04-12", business_days=True) }}, the resulting output is 1.

3. Filter for time manipulations

Convenient for adjusting appointment times for timezone differences or scheduling reminders by adding minutes or hours to specific timestamps.

Syntax: {{ value|shift_time(hours=None, minutes=None, seconds=None) }}

OperationExampleOutput
Adding seconds to a time{{ "12:30:00"|shift_time(seconds=15) }}12:30:15
Adding minutes to a time{{ "12:30:00"|shift_time(minutes=10) }}12:40:00
Adding hours to a time{{ "12:30:00"|shift_time(hours=4) }}16:30:00
Adding time to a time{{ "12:30:00"|shift_time(hours=4, minutes=10, seconds=15) }}16:40:15
Subtracting seconds from a time{{ "12:30:00"|shift_time(seconds=-15) }}12:29:45
Subtracting minutes from a time{{ "12:30:00"|shift_time(minutes=-10) }}12:20:00
Subtracting hours from a time{{ "12:30:00"|shift_time(hours=-4) }}08:30:00
Subtracting time from a time{{ "12:30:00"|shift_time(hours=-4, minutes=-10, seconds=-15) }}08:19:45

4. Filter for date/time manipulations

Useful for projecting delivery dates by adding business days to order creation timestamps or calculating deadlines by shifting dates forward or backwards based on task dependencies.

Syntax: {{ value|shift_datetime(years=None, months=None, days=None, hours=None, minutes=None, seconds=None, business_days=False) }}

OperationExampleOutput
Adding seconds to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(seconds=15) }}2024-01-11 12:30:15
Adding minutes to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(minutes=10) }}2024-01-11 12:40:00
Adding hours to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(hours=4) }}2024-01-11 16:30:00
Adding time to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(hours=4, minutes=10, seconds=15) }}2024-01-11 16:40:15
Adding days to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(days=7) }}2024-01-18 12:30:00
Adding business days to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(days=7, business_days=True) }}2024-01-22 12:30:00
Adding months to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(months=3) }}2024-04-11 12:30:00
Adding years to a datetime{{ "2024-01-11 12:30:00"|shift_datetime(years=2) }}2026-01-11 12:30:00
Subtracting seconds from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(seconds=-15) }}2024-01-11 12:29:45
Subtracting minutes from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(minutes=-10) }}2024-01-11 12:20:00
Subtracting hours from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(hours=-4) }}2024-01-11 08:30:00
Subtracting time from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(hours=-4, minutes=-10, seconds=-15) }}2024-01-11 08:19:45
Subtracting days from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(days=-7) }}2024-01-04 12:30:00
Subtracting business days from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(days=-7, business_days=True) }}2024-01-02 12:30:00
Subtracting months from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(months=-3) }}2023-10-11 12:30:00
Subtracting years from a datetime{{ "2024-01-11 12:30:00"|shift_datetime(years=-2) }}2022-01-11 12:30:00
Mixed operations{{ "2024-01-11 12:30:00"|shift_datetime(years=1, months=-2, days=8, hours=4, minutes=-10, seconds=-15) }}2024-11-19 16:19:45

5. Filter for date manipulations

Perfect for adjusting project timelines by adding or subtracting days from milestone dates or shifting event dates based on business days to accommodate working schedules.

Syntax: {{ value|shift_date(years=None, months=None, days=None, business_days=False) }}

OperationExampleOutput
Adding days to a date{{ "2024-01-11"|shift_date(days=7) }}2024-01-18
Adding business days to a date{{ "2024-01-11"|shift_date(days=7, business_days=True) }}2024-01-22
Adding months to a date{{ "2024-01-11"|shift_date(months=3) }}2024-04-11
Adding years to a date{{ "2024-01-11"|shift_date(years=2) }}2026-01-11
Subtracting days from a date{{ "2024-01-11"|shift_date(days=-7) }}2024-01-04
Subtracting business days from a date{{ "2024-01-11"|shift_date(days=-7, business_days=True) }}2024-01-02
Subtracting months from a date{{ "2024-01-11"|shift_date(months=-3) }}2023-10-11
Subtracting years from a date{{ "2024-01-11"|shift_date(years=-2) }}2022-01-11
Mixed operations{{ "2024-01-11"|shift_date(years=1, months=-2, days=8) }}2024-11-19

Why this matters

Empower your documents with these new Jinja filters. Imagine automatically calculating contract renewal dates, verifying document creation timestamps for legal compliance, or adjusting court filing deadlines based on business days - all with a few lines of code. These filters translate to real benefits: reduced errors in critical documents, improved efficiency by automating date calculations, and greater flexibility in adapting documents to specific case requirements.

Get started with these new Jinja filters and unlock a new level of efficiency in your document generation!