Day of year calculator from a calendar date
This day of year calculator converts a calendar date into its ordinal position within the year.
Run — free
Enter a date in YYYY-MM-DD format and receive an integer from 1 through 365, or through 366 in a leap year. The calculation applies Gregorian leap-year rules, validates the actual number of days in each month, and rejects impossible dates instead of silently adjusting them. It is useful wherever a human-readable date must become a compact annual index.
Turn a calendar date into an ordinal number
A day-of-year value answers a simple question: how many calendar days have elapsed from January 1 through the specified date, counting January 1 as day 1. Supply the date as four digits for the year, two for the month, and two for the day, separated by hyphens. For example, a date in early January returns a small number, while a date near the end of December returns a value close to 365 or 366. The result contains a single day_of_year integer, making it straightforward to store, compare, or pass into another calculation. The input format is deliberately strict. Values such as abbreviated years, reordered components, timestamps, and locale-dependent forms are rejected because their interpretation could vary between systems. This calculator uses the Gregorian calendar and supports years 0001 through 9999. It does not depend on the server clock, browser time zone, daylight-saving rules, or a current-date setting, so the same input always produces the same output in every supported channel.
How leap years and month lengths are handled
The ordinal is calculated by adding the complete month lengths before the requested month and then adding the requested day. February is the only month whose length changes. Under Gregorian rules, a year divisible by four is normally a leap year, but a century year is not a leap year unless it is also divisible by four hundred. Therefore 2024 and 2000 contain February 29, while 1900 and 2100 do not. That distinction matters for every date after February: March 1 is day 61 in a leap year and day 60 in a common year. Validation uses the same rules before performing the sum. April 31, February 30, day zero, month thirteen, and February 29 in a common year all produce an input error. The calculator never rolls an invalid date into the next month, a behavior some date libraries permit. This strict approach makes mistakes visible at the boundary and prevents a plausible-looking ordinal from concealing a malformed source date.
Use the result reliably in data and scheduling workflows
Ordinal days are useful when the year matters but month boundaries do not. Environmental observations can be grouped by seasonal position, manufacturing records can identify a production day compactly, and reporting pipelines can create a consistent annual sequence for charts. The value is also convenient for comparing dates within the same year, but it should not replace the original date when records may span different years: day 32 occurs every year and is not globally unique. Keep the year beside the ordinal whenever identity or chronological ordering crosses a year boundary. For recurring events, remember that leap years shift ordinal values after February 28, so a fixed calendar anniversary may have different day-of-year numbers in different years. Conversely, a fixed ordinal can resolve to a different calendar date around February in leap years. The API price is $0.002 per request, while the browser version performs the same deterministic calculation locally. Neither route needs network data, geographic location, or time-zone configuration to interpret the submitted date.
What you can do with it
Index annual observations
Convert dated weather, agriculture, or laboratory readings into a consistent position within each year for seasonal analysis.
Validate production-day labels
Check the ordinal number used in manufacturing, logistics, or batch records against the original calendar date.
Prepare dates for reporting
Add a day-of-year field to datasets and charts without relying on spreadsheet locale settings or time zones.
FAQ
What range can the result have?
The result is from 1 through 365 in a common year and from 1 through 366 in a leap year.
Which date format is accepted?
Use exactly YYYY-MM-DD, including leading zeros for one-digit months and days.
How are leap years determined?
Years divisible by four are leap years, except century years must also be divisible by four hundred.
What happens when the date is invalid?
The request returns an invalid input error for malformed dates and impossible calendar dates.
Does the calculation depend on a time zone?
No. It performs calendar arithmetic directly and does not convert the date into a timestamp.
What does the API request cost?
Each API request costs $0.002. The same calculation can also run locally in the browser.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/astro/day-of-year \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"date":"2024-12-31"}'const res = await fetch("https://api.kit.forhosting.com/astro/day-of-year", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"date": "2024-12-31"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/astro/day-of-year",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"date": "2024-12-31"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/astro/day-of-year", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"date":"2024-12-31"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"date":"2024-12-31"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/astro/day-of-year", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"date": "2024-12-31"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "astro.day_of_year",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |