Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Time
Date
Datetime
9. Defining datetime objects
Summary

Instruction

Probably the most useful objects from the datetime module are datetime objects. As you may guess, they combine date and time information. Take a look:

fra_mad_actual = datetime.datetime(2018, 12, 1, 9, 45, 0)
print(fra_mad_actual)

Result: 2018-12-01 09:45:00

We create a new datetime object by providing as many as six parameters: year, month, day, hour, minute, and second. You can also get the current point in time using the following code:

fra_mad_actual = datetime.datetime.today()

Naturally, the result will differ as time passes.

Exercise

We want to store the date and time of a budget review meeting in a variable named budget_review. The meeting is scheduled for 5 Oct 2018 at 1:30 PM. Create an appropriate datetime object and print the following:

Budget review is scheduled for {datetime}

Stuck? Here's a hint!

Remember that 1:30 PM is 13:30 in the 24-hour format!