Working with Dates and Times in Python
Max Shron
Data Scientist and Author

# Example numbers a = 11 b = 14 l = [a, b]# Find the least least in the list print(min(l)) 11

# Subtract two numbers
print(b - a)
3
# Add 3 to a
print(a + 3)
14


# Import date from datetime import date# Create our dates d1 = date(2017, 11, 5) d2 = date(2017, 12, 4) l = [d1, d2]print(min(l)) 2017-11-05

# Subtract two dates
delta = d2 - d1
print(delta.days)
29

# Import timedelta from datetime import timedelta# Create a 29 day timedelta td = timedelta(days=29) print(d1 + td) 2017-12-04
# Initialize x to be zero
x = 0
# Increment x
x = x + 1
print(x)
1
# Initialize x to be zero
x = 0
# Increment x
x += 1
print(x)
1
Working with Dates and Times in Python