Respuesta breve

API y widget integrable

Endpoints JSON documentados y un widget ISO sin seguimiento.

Respuesta breve

La API valida las entradas y devuelve códigos estables; el widget no usa fuentes externas.

Cómo funciona

CORS es restrictivo por defecto y el contrato completo está disponible en OpenAPI.

JavaScript: fecha sin desplazamiento de zona

La receta completa admite YYYY-MM-DD de 1900 a 2100, rechaza días imposibles y calcula en UTC. Para una marca de tiempo, determina primero la fecha en la zona IANA elegida. 2027-01-01 devuelve { isoYear: 2026, isoWeek: 53, isoWeekday: 5 }.

Ejecutado con Node.js 24.19.0, Python 3.14.3 y SQLite 3.53.3. Las recetas mostradas se comparan con el motor para las 73.414 fechas de 1900 a 2100 y ocho entradas no válidas.

function isoWeekDate(value) {
  if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value))
    throw new RangeError("Use a date in YYYY-MM-DD format");
  const [year, month, day] = value.split("-").map(Number);
  if (year < 1900 || year > 2100) throw new RangeError("Supported years: 1900–2100");
  const date = new Date(Date.UTC(year, month - 1, day));
  if (date.toISOString().slice(0, 10) !== value) throw new RangeError("Invalid date");
  const isoWeekday = date.getUTCDay() || 7;
  date.setUTCDate(date.getUTCDate() + 4 - isoWeekday);
  const isoYear = date.getUTCFullYear();
  const isoWeek = Math.ceil(((date.getTime() - Date.UTC(isoYear, 0, 1)) / 86400000 + 1) / 7);
  return { isoYear, isoWeek, isoWeekday };
}
isoWeekDate("2027-01-01");

Python: date.isocalendar()

Python date.isocalendar() devuelve juntos año ISO, semana y día ISO. La receta también valida el formato y el intervalo de años. Introduce una fecha, no una marca de tiempo.

from datetime import date

def iso_week_date(value):
    day = date.fromisoformat(value)
    if day.isoformat() != value or not 1900 <= day.year <= 2100:
        raise ValueError("Use YYYY-MM-DD, years 1900–2100")
    year, week, weekday = day.isocalendar()
    return {"isoYear": year, "isoWeek": week, "isoWeekday": weekday}
print(iso_week_date("2027-01-01"))

Python: datetime.date ↗

SQLite: %G / %V / %u

SQLite: vincula :date como parámetro de texto sin concatenar SQL. Combina %G y %V; %Y y %W no equivalen a ISO. WHERE rechaza fechas no válidas o no normalizadas. Las versiones antiguas sin %G/%V no sirven.

SELECT CAST(strftime('%G', :date) AS INTEGER) AS isoYear,
       CAST(strftime('%V', :date) AS INTEGER) AS isoWeek,
       CAST(strftime('%u', :date) AS INTEGER) AS isoWeekday
WHERE length(:date) = 10
  AND :date GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
  AND substr(:date, 1, 4) BETWEEN '1900' AND '2100'
  AND date(:date, '+0 days') = :date;

SQLite: date and time functions ↗

Recetas distintas para cada dialecto SQL

Estos tres ejemplos usan funciones documentadas por los fabricantes, sin ejecución local en PostgreSQL, MySQL ni SQL Server. Para 2027-01-01 se espera año ISO 2026 y semana 53. Prueba tu versión y define la zona horaria de negocio para las marcas de tiempo.

PostgreSQL: ISOYEAR + WEEK

SELECT EXTRACT(ISOYEAR FROM d)::int AS iso_year,
       EXTRACT(WEEK FROM d)::int AS iso_week
FROM (VALUES (DATE '2027-01-01')) AS dates(d);

PostgreSQL: date/time fields ↗

MySQL: YEARWEEK(date, 3)

SELECT YEARWEEK('2027-01-01', 3) DIV 100 AS iso_year,
       MOD(YEARWEEK('2027-01-01', 3), 100) AS iso_week;

MySQL: YEARWEEK ↗

SQL Server: iso_week

DECLARE @d date = DATEFROMPARTS(2027, 1, 1);
SELECT CASE
         WHEN MONTH(@d) = 1 AND DATEPART(iso_week, @d) >= 52 THEN YEAR(@d) - 1
         WHEN MONTH(@d) = 12 AND DATEPART(iso_week, @d) = 1 THEN YEAR(@d) + 1
         ELSE YEAR(@d)
       END AS iso_year,
       DATEPART(iso_week, @d) AS iso_week;

Microsoft: DATEPART ↗

REST API v1

CORS es restrictivo por defecto y el contrato completo está disponible en OpenAPI.

OpenAPI 3.1 JSON Widget

fetch("https://kalenderwoche.info/api/v1/week-from-date?date=2026-08-05")
  .then(response => response.json())