Skip to content

Instantly share code, notes, and snippets.

@juanPaclan
Last active October 16, 2017 20:57
Show Gist options
  • Save juanPaclan/bd0381f9c54391b42adf98431ae010d8 to your computer and use it in GitHub Desktop.
Save juanPaclan/bd0381f9c54391b42adf98431ae010d8 to your computer and use it in GitHub Desktop.
instalar pytho-dateutil
from dateutil.easter import *
from dateutil.relativedelta import *
from dateutil.rrule import *
from dateutil.parser import *
from datetime import *
# pip install python-dateutil
fecha-actual = datetime.today()
johnbirthday = datetime(2017, 10, 15, 10, 25)
resultado = relativedelta(fecha-actual, johnbirthday)
print(resultado)
print(resultado.days, 'dias',resultado.hours, 'horas', resultado.minutes, 'minutos')
funcion:
fecha= '2017-10-15 10:25'
def diferencia(fecha):
formato_fecha = "%Y-%m-%d %H:%M"
fecha_inicial = datetime.strptime(fecha, formato_fecha)
fecha_actual = datetime.today()
resultado = relativedelta(fecha_actual, fecha_inicial)
return resultado
resultado= diferencia(fecha)
print(resultado)
print(resultado.days, 'dias',resultado.hours, 'horas', resultado.minutes, 'minutos')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment