Misc

Calculate Date Difference

0calls
Free

Need to know how long is between two dates? This endpoint computes the precise difference.

POST
uapis.cn
/api/v1/misc/date-diff
Body
start_date
string
required

Start date. Supports auto-detection of common formats.

end_date
string
required

End date. Supports auto-detection of common formats.

format
string

Date format (optional), e.g. DD-MM-YYYY. Auto-detected when omitted.

Overview

Given a start date and an end date, the endpoint returns the difference in total days, hours, minutes, seconds, and weeks, plus a human-readable string (e.g. "1 year 2 months 3 days").

Date formats

Common formats are auto-detected, including YYYY-MM-DD, YYYY/MM/DD, DD-MM-YYYY, and ISO 8601 (with time-zone). You can also pass an explicit format (e.g. DD-MM-YYYY).

Note

When the end date precedes the start date, the returned values are negative.

Request body

start_date
stringrequired

Start date. Supports auto-detection of common formats.

end_date
stringrequired

End date. Supports auto-detection of common formats.

format
stringoptional

Date format (optional), e.g. DD-MM-YYYY. Auto-detected when omitted.

Response

200 / OK

Success. Returns the difference in multiple units.

JSON
{
  // Total days.
  "days": 364,
  // Total hours.
  "hours": 8736,
  // Total minutes.
  "minutes": 524160,
  // Total seconds.
  "seconds": 31449600,
  // Total weeks.
  "weeks": 52,
  // Human-readable summary.
  "human_readable": "52 weeks 0 days"
}

400 / Bad Request

Failed to parse a date, or invalid parameters.

JSON
{
  "error_code": "DATE_PARSE_ERROR",
  "error_message": "Failed to parse start_date: unrecognized date format: invalid-date",
  "error_details": ""
}