Skip to content

Instantly share code, notes, and snippets.

View moanesga's full-sized avatar

Mónica Espitia moanesga

View GitHub Profile
@amalgjose
amalgjose / DateDifference.py
Last active January 4, 2022 19:02
This is a very simple python code snippet for calculating the difference between two dates or timestamps. This will calculate the difference in terms of number of years, months, days, hours, minutes etc. For more details, refer https://amalgjose.com/2015/02/19/python-code-for-calculating-the-difference-between-two-time-stamps/
__author__ = 'Amal G Jose'
from datetime import datetime
from dateutil import relativedelta
##Aug 7 1989 8:10 pm
date_1 = datetime(1989, 8, 7, 20, 10)
##Dec 5 1990 5:20 am
date_2 = datetime(1990, 12, 5, 5, 20)
@moanesga
moanesga / DateDifference_YYYY,MM,DD.py
Last active June 2, 2018 12:55
Calculating range between tho given dates and printing result in X years X months X days
from datetime import datetime
from dateutil import relativedelta
a = datetime(1985,1,1)
b = datetime(2000,1,28)
delta = relativedelta.relativedelta(b,a)
years = delta.years
months = delta.months
days = delta.days
print("Range of variable hire_date is",years, "years",months, "months", days, "days")