Fechas y tiempo
Cuánto falta, cuánto pasó, y en qué formato mostrarlo. El módulo datetime.
Dates and time
How long until, how long since, and how to display it. The datetime module.
El módulo datetime viene incluido en Python. Su función más usada es
datetime.now(), que devuelve un objeto con la fecha y hora del momento exacto en
que se ejecuta.
The datetime module comes built into Python. Its most used function is
datetime.now(), which returns an object with the exact date and time it runs.
Un objeto datetime no es texto todavía. Para mostrarlo con el formato que
quieras —"11/09/2026", "11 de septiembre"— se usa .strftime() con códigos que
dicen qué parte va dónde.
A datetime object is not text yet. To display it in the format you want —
"11/09/2026", "September 11th" — you use .strftime() with codes saying what goes
where.
Restar dos fechas te da directamente cuántos días, horas y segundos hay entre ellas. El
resultado es un objeto timedelta.
Subtracting two dates gives you directly how many days, hours and seconds sit between them.
The result is a timedelta object.
Los objetos datetime se comparan igual que números, con
<, >, ==. Útil para ordenar eventos o revisar si
algo ya venció.
datetime objects compare just like numbers, with <,
>, ==. Useful for ordering events or checking if something has
already expired.
Obtener la fecha y hora actual, formatearla como texto legible, calcular cuánto tiempo hay entre dos fechas, y compararlas u ordenarlas.
Ahora, una herramienta que da miedo de lejos pero que en el fondo es simple: buscar patrones dentro de texto.
Getting the current date and time, formatting it as readable text, calculating how much time sits between two dates, and comparing or sorting them.
Now, a tool that looks scary from afar but is actually simple: finding patterns inside text.