datetime-add Edge Function — Utilities
UtilitiesAdd or subtract a duration from a date, supporting units from milliseconds to years with correct month-end handling.
Edge function datetime-add Add or subtract a duration from a date, supporting units from milliseconds to years with correct month-end handling.. 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-add 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-add",
args: {
"date": null,
"amount": 42,
"unit": "example_unit"
}
}) datetime-add — Add or subtract a duration from a date
Compute a future or past date by adding or subtracting a time duration with correct calendar handling.
API
POST /api/datetime-add
Request body
| Field | Type | Required | Description |
|---|---|---|---|
date |
string | number |
✅ | Base date (ISO string or Unix ms) |
amount |
number |
✅ | Duration to add (positive) or subtract (negative) |
unit |
string |
✅ | milliseconds, seconds, minutes, hours, days, weeks, months, years |
Success response (200)
{
"success": true,
"data": {
"result": "2024-02-15T10:00:00.000Z",
"timestamp": 1708088400000,
"original": "2024-01-15T10:00:00.000Z"
}
}
Usage
Direct import
import { datetimeAdd } from '@aerostack/functions/datetime-add';
// 30 days from now
const result = datetimeAdd({ date: Date.now(), amount: 30, unit: 'days' });
console.log(result.result); // ISO string 30 days in future
// Go back 3 months
const earlier = datetimeAdd({ date: '2024-06-15T00:00:00Z', amount: -3, unit: 'months' });
console.log(earlier.result); // "2024-03-15T00:00:00.000Z"
Use Cases
- Calculating subscription expiry dates (signup + 30 days)
- Computing trial end dates (today + 14 days)
- Building scheduling logic (event start + 2 hours = event end)
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-business-hours
by @navin
Check if a datetime falls within business hours and return the next opening time.
datetime-diff
by @navin
Calculate the difference between two dates in specified units (ms, seconds, minutes, hours, days, weeks, months, years).
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-add function do? +
datetime-add 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-add function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/datetime-add ``` It will be live on Cloudflare Workers in seconds.
What runtime does datetime-add use? +
datetime-add runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the datetime-add function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.