Jinja Templates in Workflows
Dynamic content generation with variables, expressions, and date/time operations
Jinja templates allow you to dynamically generate content in your workflows using variables, expressions, and built-in functions. This guide covers how to use Jinja templates, with a focus on date and time operations.
For simple, pre-formatted date and time values, you can use global variables like {{__exp_global.current_date}}. The datetime utilities described below provide more flexibility for custom formatting, timezone conversions, and calculations.
Basic Syntax
Jinja templates use double curly braces {{ }} for expressions and {% %} for control structures:
For more information on accessing workflow state variables, see Workflow Logic & State > State Management.
Date and Time Operations
Available Utilities
The following datetime utilities are automatically available in all Jinja templates:
datetime- Python’s datetime class for creating and manipulating dates/timestimezone- For working with UTC timezoneZoneInfo- For working with specific timezones (e.g., Pacific, Eastern)
Getting Current Time
Current UTC Time
Current Pacific Time
Other Common Timezones
Formatting Dates and Times
Use the strftime() method to format datetime objects:
Common strftime Format Codes
Converting Between Timezones
Convert a UTC datetime to Pacific time:
Creating Specific Dates
Create a datetime for a specific date and time:
Date Arithmetic
While Jinja doesn’t have built-in date arithmetic, you can work with timestamps:
Common Use Cases
Including Current Date in Messages
Generating Timestamps for Logs
Time-Sensitive Conditional Logic
Formatting Dates from Variables
If you have a date string in your workflow state, you can parse and format it:
Available Variables
In addition to datetime utilities, your templates have access to:
-
Workflow State Variables: All variables from previous blocks in your workflow
-
Global Variables: Pre-formatted date/time strings (for convenience)
For a complete list of global variables, see Workflow Logic & State > Global Variables.
- Environment Variables: Access environment variables using
_env
For more information, see Environment Variables.
Examples
Example 1: Email with Timestamp
Example 2: Dynamic Greeting Based on Time
Example 3: ISO Timestamp for API Calls
Example 4: Combining with Workflow Variables
Tips and Best Practices
-
Always specify timezones: When working with dates/times, explicitly specify the timezone to avoid ambiguity
-
Use UTC for storage/logging: Use UTC when storing timestamps or logging events
-
Format for display: Use timezone-aware datetimes when displaying to users
-
Test your templates: Verify your date/time formatting works as expected in your workflow preview
-
Choose the right tool: Use global variables for simple, pre-formatted dates. Use datetime utilities when you need custom formatting, timezone conversions, or calculations.
Additional Resources
- Workflow Logic & State - Learn about workflow state management and global variables
- Python datetime documentation
- Jinja2 template documentation
- strftime format codes reference