How to deal with Date & Time Basics in Python?
0

How to deal with Date & Time Basics in Python?

This recipe helps you deal with Date & Time Basics in Python
In [1]:
## How to deal with Date & Time Basics in Python
def Kickstarter_Example_55():
    print()
    print(format('How to deal with Date & Time Basics in Python','*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    # Load Libraries
    from datetime import datetime
    from datetime import timedelta
    # Create a variable with the current time
    now = datetime.now()
    print(); print(now)
    # The current year
    print(); print(now.year)
    # The current month
    print(); print(now.month)
    # The current day
    print(); print(now.day)
    # The current hour
    print(); print(now.hour)
    # The current minute
    print(); print(now.minute)
    # The difference between two dates
    delta = datetime(2011, 1, 7) - datetime(2011, 1, 6)
    print(); print(delta)
    # The difference days
    print(); print(delta.days)
    # The difference seconds
    print(); print(delta.seconds)
    # Create a time
    start = datetime(2018, 1, 7)
    # Add twelve days to the time
    print(); print(start + timedelta(12))

Kickstarter_Example_55()
******************How to deal with Date & Time Basics in Python*******************

2019-04-19 11:23:33.895987

2019

4

19

11

23

1 day, 0:00:00

1

0

2018-01-19 00:00:00