text: In Python language, the date and time are not the data type o their own but the datatime module provided by python can be imported to work with the 'date' and 'time'. The Datetime module is directly build into Python hence there would be no need to install it externally.
  Datetime module in python supplies classes to work with date and time. These python classes provide a number of functions to deal with dates, times and time intervals. Date and datetime are an object in Python, so when you manipulate them, you are actually manipulating objects and not string or timestamps.
  The datetime classes are categorized into 6 main classes –
  # Python program to # demonstrate date class # import the date class from datetime import date # interger
  Date passed as argument is 1996-12-11
  # Python program to # print current date from datetime import date # calling the today # function of date class today = date.today() print("Today's date is", today) # Printing date's components print("Date components", today.year, today.month, today.day)
  Today's date is 2020-05-07 Date components 2020 5 7
  import datetime datetime_object = datetime.datetime.now() print(datetime_object)
  2020-05-10 15:27:14.562891
  import datetime print(dir(datetime))
  ['MAXYEAR', 'MINYEAR', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime', 'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']
  import datetime d = datetime.date(2019, 4, 13) print(d)
  2019-04-13
  Understanding the use of 'date' when it is imported from the 'datetime' module
  from datetime import date a = date(2019, 4, 13) print(a)
  2019-04-13
  from datetime import date today = date.today() print("Current date =", today)
  Current date = 2020-05-10
  ## Get date from a timestamp from datetime import date timestamp = date.fromtimestamp(1326244364) print("Date =", timestamp)
  Date = 2012-01-11
  from datetime import date # date object of today's date today = date.today() print("Current year:", today.year) print("Current month:", today.month) print("Current day:", today.day)
  Current year: 2020 Current month: 5 Current day: 10)
  a = 00:00:00 b = 11:34:56 c = 11:34:56 d = 11:34:56.234566
  from datetime import time a = time(11, 34, 56) print("hour =", a.hour) print("minute =", a.minute) print("second =", a.second) print("microsecond =", a.microsecond)
  hour = 11 minute = 34 second = 56 microsecond = 0
  from datetime import datetime #datetime(year, month, day) a = datetime(2018, 11, 28) print(a) # datetime(year, month, day, hour, minute, second, microsecond) b = datetime(2017, 11, 28, 23, 55, 59, 342380) print(b)
  2018-11-28 00:00:00 2017-11-28 23:55:59.342380
  from datetime import datetime a = datetime(2017, 11, 28, 23, 55, 59, 342380) print("year =", a.year) print("month =", a.month) print("hour =", a.hour) print("minute =", a.minute) print("timestamp =", a.timestamp())
  year = 2017 month = 11 hour = 23 minute = 55 timestamp = 1511893559.34238))
  t3 = 201 days, 0:00:00 t6 = -333 days, 1:14:20 type of t3 = <class 'datetime.timedelta'> type of t6 = <class 'datetime.timedelta'>
  from datetime import timedelta t1 = timedelta(weeks = 2, days = 5, hours = 1, seconds = 33) t2 = timedelta(days = 4, hours = 11, minutes = 4, seconds = 54) t3 = t1 - t2 print("t3 =", t3)
  t3 = 14 days, 13:55:39
  from datetime import timedelta t = timedelta(days = 5, hours = 1, seconds = 33, microseconds = 233423) print("total seconds =", t.total_seconds())
  total seconds = 435633.233423)
  time: 15:54:33 s1: 05/10/2020, 15:54:33 s2: 10/05/2020, 15:54:33