References 1. Python for Data analysis 2. Useful Links https://docs.python.org/2/library/datetime.html
Step1: import packages from library
from datetime import datetime, date, time,timedeltaBackground information,
date: contain attributes like year, month, day time: contain attributes like hour, minute, second, microsecond and tzinfo datetime: a combination of date and time, provide attributes year, month, day, hour, minute, second, microsecond, and tzinfo. timedelta: represents a duration, the difference between two dates or times.
from datetime import timedelta d = timedelta(microseconds=-1) (d.days, d.seconds, d.microseconds)Step2: Application of datetime
create user-written datetimedt = datetime(2017,02,04,15,05,55) –> 2017/02/04 15:05:55
manipulation of datetime add 1 day to ‘dt’ dt2 = dt + timedelta(second = 86400) –> 2017/02/05 15:05:55 the difference between two dates (dt2 - dt).total_seconds()—> Return the total number of seconds contained in the duration