datetime-diff Edge Function — Utilities
UtilitiesCalculate the difference between two dates in specified units (ms, seconds, minutes, hours, days, weeks, months, years).
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.
npx aerostack add navin/datetime-diff Use with AI Assistants
MCPConnect 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.
{
"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({
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
Tags
Publisher
@navin verified
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 →datetime-add
by @navin
Add or subtract a duration from a date, supporting units from milliseconds to years with correct month-end handling.
datetime-business-hours
by @navin
Check if a datetime falls within business hours and return the next opening time.
datetime-duration-format
by @navin
Format a duration in milliseconds to a human-readable string with long, short, or compact styles.
datetime-format
by @navin
Format a date to a string using format tokens like YYYY-MM-DD HH:mm:ss with optional timezone support.
datetime-parse
by @navin
Parse a date string or unix timestamp to a normalised Unix millisecond timestamp and ISO string.
datetime-relative
by @navin
Format a date as a relative time string like '2 hours ago' or 'in 3 days' using Intl.RelativeTimeFormat.
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.