Aerostack
build

datetime-add Edge Function — Utilities

Utilities

Add or subtract a duration from a date, supporting units from milliseconds to years with correct month-end handling.

navin @navin verified
Updated Mar 12, 2026
GitHub

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.

terminal — aerostack cli
$ npx aerostack add navin/datetime-add
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-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

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-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.