Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Operations with Dates | Dates and Times Project
Organizing Date and Time Data for Analysis and Applications

book
Operations with Dates

Now that you have understood what datetime objects are and how you can transform them, we can introduce the timedelta() function. timedelta() allows you to alter your dates by adding a delta to your dates (days, months, ecc..). We will also show how easy it is to find the difference between two dates.

Tarea

Swipe to start coding

  1. Import the datetime library with the timedelta module;
  2. Find the difference between two dates;
  3. Add 30 days to the date1 variable.

Solución

from datetime import datetime, timedelta

date1 = datetime(2022, 1, 8)
date2 = datetime(2022, 1, 12)
difference = date2 - date1
print(difference)

date1 += timedelta(days = 30)
print(date1)

Mark tasks as Completed
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt