Time/Timezone Utilities

Time Difference

Calculate precise time differences between two datetime values, returning results in multiple units (seconds, minutes, hours, days). Use via MCP in Cursor or Claude Code, or call GET /v1/time/difference directly. Perfect for scheduling logic, SLA tracking, or duration calculations. Handles timezone-aware inputs and provides both absolute and signed differences.

API Endpoint

GET /v1/time/difference

Code Examples

curl "https://tinyfn.io/v1/time/difference" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/time/difference', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/time/difference',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's time/timezone tools:

{
  "mcpServers": {
    "tinyfn-time": {
      "url": "https://tinyfn.io/mcp/time",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I calculate time difference between two dates using MCP?

Pass two datetime strings to the time difference tool in your MCP-enabled editor. It returns the difference in seconds, minutes, hours, and days, plus whether the first date is before or after the second.

What datetime formats does the time difference API accept?

Accepts ISO 8601 formats, Unix timestamps, and common date strings. Timezone information is preserved when provided, otherwise UTC is assumed.

Can I get negative time differences for past dates?

Yes, the tool returns signed differences. If the first datetime is earlier than the second, you'll get negative values indicating the first date is in the past relative to the second.

How accurate are time difference calculations across timezones?

Extremely accurate. The tool properly handles timezone offsets, daylight saving time transitions, and leap seconds when calculating differences between timezone-aware datetimes.

What's the difference between this and simple date subtraction?

This tool handles complex scenarios like timezone conversions, DST changes, and provides results in multiple units simultaneously. Simple subtraction often fails with timezone-aware dates or gives incorrect results during DST transitions.

Try Time Difference Now

Get your free API key and start using Time Difference in seconds.

Get Free API Key