Forked from juanPaclan/gist:f618e49cffd17b21296bbefafbe6d100
Created
July 17, 2019 22:37
-
-
Save 3l3n01/b5c40e053980dc378cbeef457c314aca to your computer and use it in GitHub Desktop.
diferencia de fecha python
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 | |
formato_fecha = "%Y-%m-%d %H:%M:%S" | |
fecha = datetime.today() | |
fecha_actual= fecha.strftime(formato_fecha) | |
fecha_inicial = datetime.strptime("2017-10-10 03:12:50",formato_fecha) | |
fecha_final = datetime.strptime(fecha_actual, formato_fecha) | |
diferencia = fecha_final - fecha_inicial | |
horas= diferencia.seconds/3600 | |
residuo= int(diferencia.seconds) - int(horas*3600) | |
minutos= residuo/60 | |
segundos= residuo-int(minutos*60) | |
print(diferencia.seconds, residuo, segundos ) | |
print("Fecha inicial:", fecha_inicial) | |
print("Fecha final:", fecha_final) | |
print("Diferencia:", diferencia) | |
print("Diferencia:", diferencia.days, "dias", horas , "horas", minutos, "minutos" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment