datetime Module

The topic today is datetime which makes me think of life. Maybe, music is a mataphor of life.

1
2
3
4
5
6
7
import datetime

t = datetime.date(2017, 4, 4)
t.isoweekday() # 2
t.isoformat() # '2017-04-04'

one_day = datetime.timedelta(days=1)

Other things useless (maybe not) you could find on
https://docs.python.org/3/library/datetime.html

1
2
3
4
5
6
7
8
9
10
11
12
import time
from datetime import date

today = date.today()
today == date.fromtimestamp(time.time()) # True
my_birthday = date(today.year, 6, 24) # Fake birthday

if my_birthday < today:
my_birthday = my_birthday.replace(year=today.year + 1)

time_to_birthday = abs(my_birthday - today) # why we need abs that makes previous IF statement meaningless
time_to_birthday.days

You could always find the manual. That’s enough for today.