Created
June 7, 2018 12:11
-
-
Save Fhernd/2995910ddabcb7809bff5704dd4503c2 to your computer and use it in GitHub Desktop.
Calcular rango de fechas. OrtizOL.
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, date, timedelta | |
import calendar | |
def calcular_rango_fechas(fecha_inicio=None): | |
if fecha_inicio is None: | |
fecha_inicio = date.today().replace(day=1) | |
_, dias_mes = calendar.monthrange(fecha_inicio.year, fecha_inicio.month) | |
fecha_final = fecha_inicio + timedelta(days=dias_mes) | |
return (fecha_inicio, fecha_final) | |
dia = timedelta(days=1) | |
primer_dia, ultimo_dia = calcular_rango_fechas() | |
while primer_dia < ultimo_dia: | |
print(primer_dia) | |
primer_dia += dia |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment