Aerostack
build

datetime-diff Edge Function — Utilities

Utilities

Calculate the difference between two dates in specified units (ms, seconds, minutes, hours, days, weeks, months, years).

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function datetime-diff Calculate the difference between two dates in specified units (ms, seconds, minutes, hours, days, weeks, months, years).. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/datetime-diff
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "datetime-diff",
  args: {
    "from": null,
    "to": null,
    "unit": "example_unit"
  }
})

datetime-diff — Calculate the difference between two dates

Get the signed or absolute difference between two dates in any time unit from milliseconds to years.


API

POST /api/datetime-diff

Request body

Field Type Required Description
from string | number Start date (ISO string or Unix ms)
to string | number End date (ISO string or Unix ms)
unit string milliseconds, seconds, minutes, hours, days, weeks, months, years

Success response (200)

{
  "success": true,
  "data": {
    "diff": 5,
    "absolute": 5,
    "unit": "days",
    "from": "2024-01-15T00:00:00.000Z",
    "to": "2024-01-20T00:00:00.000Z"
  }
}

Usage

Direct import
import { datetimeDiff } from '@aerostack/functions/datetime-diff';

const result = datetimeDiff({
  from: '2024-01-01T00:00:00Z',
  to: '2024-12-31T00:00:00Z',
  unit: 'days',
});
console.log(result.diff); // 365

Use Cases

  • Calculating days remaining until a subscription expires
  • Showing elapsed time since a user signed up
  • Checking if two events are within N hours of each other

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

datetime
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Utilities Functions

Browse Utilities Functions →

Frequently asked questions

What does the datetime-diff function do? +

datetime-diff is a serverless edge function for utilities automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the datetime-diff function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/datetime-diff ``` It will be live on Cloudflare Workers in seconds.

What runtime does datetime-diff use? +

datetime-diff runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the datetime-diff function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.