Skip to content

[FEATURE] Tool for relative date calculation #422

@shubham-patel26

Description

@shubham-patel26

Problem Statement

Currently, Strands does not any tool for calculating relative dates/time like :

  1. "what was the date 3 months ago?" or
  2. "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

  1. Month-end clamping: Jan 31 + 1 month → Feb 28 (or 29 in leap years)
  2. Leap year transitions: Feb 29, 2024 + 1 year → Feb 28, 2025
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions