Method Deck / dates
Day of year and days remaining
Computes a date's ordinal position within its calendar year and how many days are left in that year.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
- date (string, required) : ISO 8601 date, YYYY-MM-DD
Outputs
- day_of_year (days): Ordinal day within the year, 1 to 365 or 366
- days_remaining (days): Days left in the calendar year after this date
Steps
- Parse the date as a proleptic Gregorian civil date.
- Convert the date and January 1 of the same year to Julian Day Numbers (Hinnant days_from_civil, cited above).
- day_of_year = JDN(date) - JDN(year, 1, 1) + 1.
- days_in_year = 366 if the year is a Gregorian leap year, else 365.
- days_remaining = days_in_year - day_of_year.
Constants
None.
Sources
Worked example and test vectors
| Name | Inputs | Answer |
| worked example | {"date":"2024-03-01"} | Day 61 of 366; 305 days remaining in the year |
| test vector: last day of a non-leap year | {"date":"2023-12-31"} | Day 365 of 365; 0 days remaining in the year |
| test vector: first day of year | {"date":"2026-01-01"} | Day 1 of 365; 364 days remaining in the year |
Published card
- Address:
4a7ea29599fbd053377815d25a262e5b
- Made at:
2026-09-30T22:39:30.722Z
- Method sha256:
09ba5314b5d4ca8115a7edcc1f2b4a0e3b330d8f55cc6c234964bb1150260ddb