This section has some short exercises to illustrate the features of time series elements:
- Import the inbuilt datetime Python package, as shown:
from datetime import datetime
- To get the current date/time which is the timestamp, do the following:
timestamp_now = datetime.now()
datetime(2018, 3, 14, 0, 10, 2, 17534)
By executing the preceding code you'll get the following output:
datetime.datetime(2018, 3, 14, 0, 10, 2, 17534)
- You can get the difference between two timestamps by just doing the following:
time_difference = datetime(2018,3,14) - datetime(2015,2,13,0,59)
datetime.timedelta(1124, 82860)
- You can extract the day from the preceding code by:
time_difference.days = 1124
- You can extract the seconds by:
time_difference.seconds = 82860
- Date times can also be added to each other.