[FEATURE] Tool for relative date calculation
Problem Statement
Currently, Strands does not any tool for calculating relative dates/time like :
- "what was the date 3 months ago?" or
- "which contract was active(based on data retreived from DB) last year in January?"
In such cases, Strands does not have in-built support and clients have to write their custom tool for relative date calculation.
Proposed Solution
Add a tool say calculate_date which will return the dates in ISO format for cases like :
from strands_tools import calculate_date
# Get today's date (agents should call this instead of guessing)
calculate_date(offset_type="days", offset_value=0)
# → {"date": "2026-03-23"}
# 6 months ago
calculate_date(offset_type="months", offset_value=-6)
# → {"date": "2025-09-23"}
# 90 days from a specific date
calculate_date(offset_type="days", offset_value=90, base_date="2024-01-15")
# → {"date": "2024-04-14"}
Use Case
Analytics/reporting agents ("compare this month vs last month") Scheduling/calendar agents ("book something 2 weeks from now") Compliance/audit agents ("show records from the past 90 days") Financial agents ("what was the rate on January 15 last year?") Any agent chaining with time-filtered APIs or databases
Alternatives Solutions
No response
Additional Context
Edge Cases Handled
- Month-end clamping: Jan 31 + 1 month → Feb 28 (or 29 in leap years)
- Leap year transitions: Feb 29, 2024 + 1 year → Feb 28, 2025
- Year rollovers: Jan 15 - 2 months → Nov 15 (previous year)
Dependency: python-dateutil (already widely used, handles relativedelta for months/years) Would fit naturally alongside existing strands_tools like file_read, shell, etc. We've deployed this in a production Strands agent and validated it handles all the edge cases above Happy to contribute a PR if the team is open to it
While building our AI chatbot we faced this issue that LLM is not aware and can't perform relative date calculation so we built a custom tool for our use case. I am interested to contribute that tool as an in-built tool for Strands
Opened #441 with this tool implementation. Handles all the edge cases mentioned (month-end clamping, leap years, year rollovers).
We've been scaling back on accepting new tools in this repo due to maintenance and scalability concerns. We're pushing new tools to standalone community packages instead.
Thanks for the detailed write-up and edge case handling. Since you mentioned you already have this deployed in production, publishing it as a standalone package should be straightforward. We've also closed the related PR #441. You can use our extension template to scaffold it and get featured in our docs. Check out the links below:
- Extension template: https://github.com/strands-agents/extension-template-python
- Get featured in docs: https://strandsagents.com/docs/community/get-featured/