import time as tm
#Convert Date to Fiscal Year/Fiscal Week
The Python Programming Language: Dates and Times
import datetime as dt
import time as tm
time returns the current time in seconds since the Epoch. (January 1st, 1970)
tm.time()
1525223257.9893782
Convert the timestamp to datetime.
dtnow = dt.datetime.fromtimestamp(tm.time())
dtnow
datetime.datetime(2018, 5, 2, 9, 7, 42, 402702)
Handy datetime attributes:
dtnow.year, dtnow.month, dtnow.day, dtnow.hour, dtnow.minute, dtnow.second # get year, month, day, etc.from a datetime
(2018, 5, 2, 9, 7, 42)
timedelta is a duration expressing the difference between two dates.
delta = dt.timedelta(days = 100) # create a timedelta of 100 days
delta
datetime.timedelta(100)
date.today returns the current local date.
today = dt.date.today()
today - delta # the date 100 days ago
datetime.date(2018, 1, 22)
today > today-delta # compare dates
True