Date Calculator API

A lightweight REST API that calculates a missing date value given any two of start, end, and duration, with a unit of days, weeks, months, or business (Mon–Fri).

Base URL

https://www.promptbox.cn/api/date.php

Methods

GET and POST (JSON or form)

Query Parameters (GET)

Parameter Type Required Example Description
start string (YYYY-MM-DD) No (need any two) 2025-01-01 Start date
end string (YYYY-MM-DD) No (need any two) 2025-01-31 End date
duration integer No (need any two) 30 Duration amount (≥ 0)
unit string No days One of days, weeks, months, business. Default: days

Request Body (POST JSON)

{
  "start": "2025-01-01",
  "duration": 30,
  "unit": "days"
}

Response

Success

{
  "success": true,
  "data": {
    "start": "2025-01-01",
    "end": "2025-01-31",
    "duration": 30,
    "unit": "days"
  }
}

Error

{
  "success": false,
  "error": "Please provide at least two of: start, end, duration."
}

Examples

1) Compute End from Start + Duration (Days)

GET /api/date.php?start=2025-01-01&duration=30&unit=days
{
  "success": true,
  "data": {
    "start": "2025-01-01",
    "end": "2025-01-31",
    "duration": 30,
    "unit": "days"
  }
}

2) Compute Start from End + Duration (Weeks)

GET /api/date.php?end=2025-04-07&duration=2&unit=weeks
{
  "success": true,
  "data": {
    "start": "2025-03-24",
    "end": "2025-04-07",
    "duration": 2,
    "unit": "weeks"
  }
}

3) Compute Duration from Start + End (Months)

GET /api/date.php?start=2025-01-15&end=2025-04-10&unit=months
{
  "success": true,
  "data": {
    "start": "2025-01-15",
    "end": "2025-04-10",
    "duration": 3,
    "unit": "months"
  }
}

4) Business Days Example

POST /api/date.php
Content-Type: application/json

{
  "start": "2025-01-02",
  "duration": 5,
  "unit": "business"
}
{
  "success": true,
  "data": {
    "start": "2025-01-02",
    "end": "2025-01-09",
    "duration": 5,
    "unit": "business"
  }
}

5) Error Example

GET /api/date.php?unit=days
{
  "success": false,
  "error": "Please provide at least two of: start, end, duration."
}

Notes