Created
March 17, 2022 15:48
-
-
Save gcrsaldanha/6841e0ddabe863688b8d0e4b56239deb to your computer and use it in GitHub Desktop.
Criando datetimes de 30 em 30 minutos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
dt_inicio = datetime(2022, 3, 17, 9) # 09h00, 17 de Março de 2022 | |
dt_fim = datetime(2022, 3, 17, 18) # 18h00, 17 de Março de 2022 | |
delta = timedelta(minutes=30) # objeto timedelta de 30 minutos | |
dt = dt_inicio + delta | |
print(type(dt)) | |
# <class 'datetime.datetime'> | |
print(dt) | |
# >>> 2022-03-17 09:30:00 | |
# Obs: quando somamos um timedelta a um datetime, é retornado um novo objeto datetime com os valores atualizados. | |
# Como podemos gerar vários objetos datetime nos horários de 30 em 30 minutos? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment