2 Ways to adjust dates in Pipelines using Jinja
Jun 09, 2021>> Get the Jinja Date & Time Cheat Sheet <<
Relative dates are used all the time, so why not use them in Pipelines!
For example, add a task to a project that has a due date of 2 days from the project start date.
Or set a next payment due date for the first of the month following receipt of this month's payment.
Or maybe you just need to set the end time for a meeting 1 hour after the start.
By adding Jinja to your Pipeline, you can take an initial date or date/time value and derive a new 'adjusted' time value.
With 2 Jinja functions, it's possible to...
- Add or subtract days, months, or years from today
- Add or subtract days, months, or years from another date
- Add or subtract hours, minutes, or seconds from any date/time
- Replace one or more values in a date with a specific month, day, or year
- Replace one or more values in a time with a specific hour, minute or second
The Jinja Functions
time.delta()
Used to offset a date/time value by a specified amount of time, such as hours, days, or months.
.replace()
Replaces the day, month, or year in a date value or hour, minute, and second in a date/time value.
A Few Examples
Add 3 hours to the Current Time
{{ time.now + time.delta(hours=3) }}
With an adjustment for timezone:
{{ (time.now|timezone('America/New_York')) + time.delta(hours=3) }}
Add 3 days to a Start Date field from step A in the Pipeline
{{ a.start_date + time.delta(days=3) }}
Adjusting for both days and months:
{{ a.start_date + time.delta(months=2,days=3) }}
Add 1 month to a Due Date field and set the date to the 1st
{{ a.due_date.replace(day=1) + time.delta(months=1) }}
Be sure to watch the video for more examples and tips.
These date/time adjustments are sure to come in handy!
Don't forget, there are 6 different areas where Jinja and these adjusted dates/times can be used in Pipelines (covered in the Jinja Date & Time Cheat Sheet).
For more information on Jinja see the resources below, or skip right to the good stuff and get the Intro to Jinja for Pipelines course today!
RESOURCES:
Get the FREE Jinja Date & Time Cheat Sheet mentioned in this video
Learn more about how Jinja works in Pipelines
Feeling like a Junkie? Subscribe Now!