Skip to content

Instantly share code, notes, and snippets.

@renegarcia
Created December 16, 2023 17:27
Show Gist options
  • Save renegarcia/383a36e0d08c62484407c749d51eca4f to your computer and use it in GitHub Desktop.
Save renegarcia/383a36e0d08c62484407c749d51eca4f to your computer and use it in GitHub Desktop.
Elapsed days from daterange
from datetime import datetime
# Formato de la fecha: 'dd-mm-yyyy'
fecha_inicio = '01-01-2023'
fecha_fin = '16-12-2023'
# Convertir las cadenas a objetos datetime
fecha_inicio = datetime.strptime(fecha_inicio, '%d-%m-%Y')
fecha_fin = datetime.strptime(fecha_fin, '%d-%m-%Y')
# Calcular la diferencia entre las fechas
diferencia = fecha_fin - fecha_inicio
# Imprimir el número de días
print('Número de días transcurridos:', diferencia.days)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment