MCP Tools for Date/Time Calculations

"What date is 3 weeks from now?" seems like an easy question. But ask an LLM on January 30th and you might get February 20th (wrong), February 21st (maybe), or even March 1st (definitely wrong). Here's why AI fails at dates and how MCP tools fix it.

Why LLMs Fail at Date Math

Large Language Models are trained on text, not calendars. When they encounter date questions, they're essentially pattern-matching against examples they've seen, not computing actual dates.

Common Date Calculation Failures

Problem What LLMs Often Miss
Month lengths February has 28/29 days, months vary from 28-31
Leap years 2024 is a leap year, 2100 isn't (century rule)
Weekends Business day calculations skip Sat/Sun
DST transitions Clocks shift, affecting time calculations
Timezone offsets Not all zones are whole-hour offsets

Example of LLM Date Failure

Without MCP Tools
User: "It's January 30, 2025. When is 30 days from now?"

LLM: "30 days from January 30, 2025 is February 29, 2025."

Reality: February 29, 2025 doesn't exist!
         2025 is not a leap year.
         Correct answer: March 1, 2025
The Core Problem: LLMs don't have a running calendar. They don't know "today's date" unless you tell them, and even then, they approximate rather than calculate.

TinyFn DateTime Endpoints

TinyFn provides a comprehensive set of datetime tools via MCP. These tools actually compute dates using proper calendar libraries.

Available DateTime Tools

Tool Purpose
datetime/now Get current date/time in any timezone
datetime/add Add years, months, days, hours to a date
datetime/difference Calculate time between two dates
datetime/add-business-days Add days excluding weekends
datetime/format Format dates in any pattern
datetime/parse Parse dates from various formats
datetime/start-of Get start of day/week/month/year
datetime/end-of Get end of day/week/month/year

Basic Date Addition

API Request - Add 30 Days
GET https://api.tinyfn.io/v1/datetime/add?date=2025-01-30&days=30
Headers: X-API-Key: your-api-key
Response
{
  "original": "2025-01-30T00:00:00.000Z",
  "result": "2025-03-01T00:00:00.000Z",
  "added": {
    "days": 30
  },
  "formatted": "Saturday, March 1, 2025"
}

Timezone Handling

Timezone calculations are notoriously tricky. TinyFn uses the IANA timezone database and handles all the edge cases automatically.

Convert Between Timezones

Timezone Conversion
GET https://api.tinyfn.io/v1/time/convert
  ?datetime=2025-01-30T15:00:00
  &from=America/New_York
  &to=Asia/Tokyo
Response
{
  "from": {
    "datetime": "2025-01-30T15:00:00-05:00",
    "timezone": "America/New_York",
    "offset": "-05:00"
  },
  "to": {
    "datetime": "2025-01-31T05:00:00+09:00",
    "timezone": "Asia/Tokyo",
    "offset": "+09:00"
  },
  "difference_hours": 14
}

DST-Aware Calculations

TinyFn automatically handles Daylight Saving Time transitions:

DST Handling
// Adding 1 day across DST transition
GET https://api.tinyfn.io/v1/datetime/add
  ?date=2025-03-08T12:00:00
  &timezone=America/New_York
  &days=1

// Returns March 9th, 2025 at 12:00 PM EST (not 11 AM or 1 PM)
// Correctly handles the "spring forward" transition

Business Days and Holidays

One of the most common date calculation needs is business day math. "When will this ship if we process in 5 business days?" requires skipping weekends and potentially holidays.

Add Business Days

Business Days Calculation
GET https://api.tinyfn.io/v1/datetime/add-business-days
  ?date=2025-01-30
  &days=5
Response
{
  "start_date": "2025-01-30",
  "business_days_added": 5,
  "result": "2025-02-06",
  "calendar_days": 7,
  "skipped_weekend_days": 2
}

Include Holiday Exclusions

Business Days with Holidays
GET https://api.tinyfn.io/v1/datetime/add-business-days
  ?date=2025-12-20
  &days=5
  &holidays=2025-12-25,2025-12-26,2026-01-01
Response
{
  "start_date": "2025-12-20",
  "business_days_added": 5,
  "result": "2025-12-31",
  "calendar_days": 11,
  "skipped_weekend_days": 2,
  "skipped_holidays": ["2025-12-25", "2025-12-26"]
}

Calculate Business Days Between Dates

Business Day Count
GET https://api.tinyfn.io/v1/datetime/business-day-difference
  ?start=2025-01-01
  &end=2025-01-31
Response
{
  "start": "2025-01-01",
  "end": "2025-01-31",
  "business_days": 22,
  "calendar_days": 30,
  "weekends": 8
}

Real-World Examples

Shipping Estimate Calculation

E-commerce Shipping
// Customer orders on Friday afternoon
// Warehouse processes next business day
// Then 3-5 business days for shipping

// Step 1: Get next business day (processing day)
datetime/add-business-days?date=2025-01-31&days=1
// Result: 2025-02-03 (Monday)

// Step 2: Add shipping window
datetime/add-business-days?date=2025-02-03&days=3
// Result: 2025-02-06 (Thursday) - earliest arrival

datetime/add-business-days?date=2025-02-03&days=5
// Result: 2025-02-10 (Monday) - latest arrival

// Response: "Arrives Feb 6-10"

Subscription Renewal Date

SaaS Billing
// User signed up January 31
// Monthly subscription - when's next billing?

datetime/add?date=2025-01-31&months=1
// Result: 2025-02-28 (last day of Feb, since Feb 31 doesn't exist)

// The tool correctly handles month-end edge cases!

International Meeting Scheduler

Multi-timezone Meeting
// Find a meeting time that works for NYC, London, and Tokyo

// Propose 9 AM EST
time/convert?datetime=2025-01-30T09:00&from=America/New_York&to=Europe/London
// Result: 2:00 PM GMT

time/convert?datetime=2025-01-30T09:00&from=America/New_York&to=Asia/Tokyo
// Result: 11:00 PM JST

// That's too late for Tokyo. Try 7 AM EST instead:
time/convert?datetime=2025-01-30T07:00&from=America/New_York&to=Asia/Tokyo
// Result: 9:00 PM JST - Better!

Age Calculator

Calculate Exact Age
datetime/difference?start=1990-06-15&end=2025-01-30
Response
{
  "difference": {
    "years": 34,
    "months": 7,
    "days": 15
  },
  "total_days": 12648,
  "human_readable": "34 years, 7 months, 15 days"
}

Integration Guide

MCP Configuration

mcp.json
{
  "mcpServers": {
    "tinyfn-datetime": {
      "url": "https://api.tinyfn.io/mcp/datetime/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

Python Integration

import requests

class DateTimeTools:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = "https://api.tinyfn.io/v1"

    def add_business_days(self, date, days, holidays=None):
        params = {"date": date, "days": days}
        if holidays:
            params["holidays"] = ",".join(holidays)

        response = requests.get(
            f"{self.base_url}/datetime/add-business-days",
            params=params,
            headers={"X-API-Key": self.api_key}
        )
        return response.json()

    def convert_timezone(self, datetime_str, from_tz, to_tz):
        response = requests.get(
            f"{self.base_url}/time/convert",
            params={"datetime": datetime_str, "from": from_tz, "to": to_tz},
            headers={"X-API-Key": self.api_key}
        )
        return response.json()

# Usage
tools = DateTimeTools("your-api-key")
shipping_date = tools.add_business_days("2025-01-30", 5)
print(shipping_date["result"])  # 2025-02-06

JavaScript Integration

class DateTimeTools {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://api.tinyfn.io/v1';
  }

  async addBusinessDays(date, days, holidays = []) {
    const params = new URLSearchParams({ date, days });
    if (holidays.length) {
      params.set('holidays', holidays.join(','));
    }

    const response = await fetch(
      `${this.baseUrl}/datetime/add-business-days?${params}`,
      { headers: { 'X-API-Key': this.apiKey } }
    );
    return response.json();
  }

  async convertTimezone(datetime, fromTz, toTz) {
    const params = new URLSearchParams({ datetime, from: fromTz, to: toTz });
    const response = await fetch(
      `${this.baseUrl}/time/convert?${params}`,
      { headers: { 'X-API-Key': this.apiKey } }
    );
    return response.json();
  }
}

// Usage
const tools = new DateTimeTools('your-api-key');
const result = await tools.addBusinessDays('2025-01-30', 5);
console.log(result.result); // 2025-02-06

Never Get Date Calculations Wrong Again

Give your AI agents access to accurate datetime tools via MCP.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key