Date Difference

Date Difference

Math & Calculations Credits / request: 1

Returns days, hours, months, years and age between two dates.

GET https://api.apikodu.com/api/v1/math/datediff
Documentation
Overview

Difference between two dates (days, hours, age).

Authentication

Every request requires the x-api-key header. Credits used and remaining quota are returned in response headers (x-api-credits-used, x-api-remaining-credits, x-rate-limit-*).

Request
GET https://api.apikodu.com/api/v1/math/datediff?fromDate=1990-08-02&toDate=2026-08-22
Query string. YYYY-MM-DD.
Parameters
Name Type Required Default Options Description
fromDate string * Required — — Start.
toDate string * Required — — End.
Response
Name Type Description
days integer Whole days between the two dates (|to − from|).
hours integer The same difference in hours (days * 24).
minutes integer The same difference in minutes (hours * 60).
years integer Calendar year difference (whole years).
months integer Remaining month difference after years (0–11).
daysRemainder integer Remaining days after years and months.
age integer Age at toDate if fromDate is a birth date. Same as years.
fromDate string Normalized start YYYY-MM-DD.
toDate string Normalized end YYYY-MM-DD.
Errors
HTTP code Description
400 -247 fromDate or toDate is missing or not YYYY-MM-DD.
401 -100 x-api-key is missing, empty, malformed, inactive, banned, expired, IP-restricted, or not allowed for this API.
429 -221 Per-minute request limit exceeded. Response headers: x-rate-limit-limit, x-rate-limit-remaining, x-rate-limit-reset.
429 — Package credit quota cannot cover this request. Body may be { error, limit, currentUsage, requestCost } (no code field).
500 -1 Unexpected server error. message is a generic error text without technical details.
Notes
  • Success body is { data: { ... } }. Error body is { code, message }. code is an ApiResponseCode enum value (negative integer).

Sample response

{
  "data": {
    "days": 13138,
    "hours": 315312,
    "minutes": 18918720,
    "years": 36,
    "months": 0,
    "daysRemainder": 20,
    "age": 36,
    "fromDate": "1990-08-02",
    "toDate": "2026-08-22"
  }
}

Code samples

  
      const response = await fetch('https://api.apikodu.com/api/v1/math/datediff', {
        method: 'GET',
        headers: {
          'x-api-key': 'YOUR_API_KEY'
        }
      });

      const data = await response.json();
      console.log(data);
  
  
      import requests

      headers = {
          'x-api-key': 'YOUR_API_KEY'
      }

      response = requests.get('https://api.apikodu.com/api/v1/math/datediff', headers=headers)
      print(response.json())
  
  
      using var client = new HttpClient();
      client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");

      var response = await client.GetStringAsync("https://api.apikodu.com/api/v1/math/datediff");
      Console.WriteLine(response);
  
  
      $response = file_get_contents('https://api.apikodu.com/api/v1/math/datediff', false, stream_context_create([
          'http' => [
              'header' => "x-api-key: YOUR_API_KEY"
          ]
      ]));

      print_r(json_decode($response, true));
  
  
      curl -X GET 'https://api.apikodu.com/api/v1/math/datediff' \
        -H 'x-api-key: YOUR_API_KEY'
  

Start building in minutes

Create a free account, get your API key and send your first request in minutes.

Get started free