Module Overview
This module introduces Python's date and time functionality, enabling learners to work with dates, times, durations and time zones within their programs. Learners explore the datetime module and its associated objects, including date, time, datetime, timedelta, timezone and tzinfo.
The module also covers formatting and parsing date and time values using strftime() and strptime(), helping learners manage date-related information, calculate durations, organise schedules and handle time-based data.
These concepts are useful for developing business applications that manage deadlines, schedules, transaction dates, reporting periods and time-sensitive operations.
What Will Be Covered
1. datetime – Basic Date and Time Types
Understand the Python datetime module and the fundamental types used to work with dates and times.
Introduction to the
datetimemodule.Understanding date and time data.
Exploring the basic date and time types.
Working with date and time representations.
Understanding date and time-related operations.
Using the
datetimemodule in Python programs.
Practical example: Develop programs that record transaction dates, track deadlines or manage dates associated with business records.
2. timedelta Objects
Learn how Python represents time durations and how timedelta objects are used to calculate differences and perform date and time arithmetic.
Introduction to
timedelta.Representing durations and time differences.
Calculating differences between dates and times.
Adding durations to dates and times.
Subtracting durations from dates and times.
Working with days, seconds and other duration values.
Applying timedelta calculations.
Practical example: Calculate project durations, delivery timelines, payment deadlines or the number of days between business events.
3. date Objects
Understand how Python's date objects represent calendar dates and support date-based calculations and operations.
Introduction to date objects.
Creating date objects.
Accessing year, month and day values.
Working with calendar dates.
Comparing dates.
Performing date-based calculations.
Applying date operations in Python programs.
Practical example: Calculate due dates, track project milestones, identify reporting periods or compare dates associated with business transactions.
4. datetime Objects
Learn how Python's datetime objects combine date and time information to support more detailed time-based operations.
Introduction to datetime objects.
Creating datetime objects.
Working with date and time components.
Accessing datetime attributes.
Comparing datetime values.
Performing datetime calculations.
Working with datetime operations.
Practical example: Record transaction timestamps, track when activities occur or calculate the duration between scheduled events.
5. time Objects
Understand how Python's time objects represent time independently of a calendar date.
Introduction to time objects.
Creating time objects.
Working with hours, minutes, seconds and microseconds.
Accessing time components.
Comparing time values.
Working with time-based operations.
Practical example: Manage business operating hours, meeting schedules, shift timings or time-based conditions within a Python program.
6. tzinfo Objects
Learn how Python uses tzinfo to represent and manage time zone information within date and time objects.
Introduction to
tzinfo.Understanding time zone information.
Working with timezone-aware datetime objects.
Understanding time zone offsets.
Applying time zone information to datetime values.
Understanding the role of
tzinfoin time zone management.
Practical example: Understand how time zone information supports scheduling meetings, managing international operations and handling timestamps across different locations.
7. Timezone Objects
Explore Python's timezone objects and how they help represent time zone offsets and manage time zone-aware date and time values.
Introduction to timezone objects.
Creating timezone objects.
Working with timezone offsets.
Applying timezone information to datetime objects.
Understanding timezone-aware values.
Managing date and time values across time zone differences.
Practical example: Handle scheduled activities across different time zones when coordinating meetings, business operations or time-based records.
8. strftime() and strptime()
Learn how Python formats date and time values into readable strings and converts formatted strings into date and time objects.
Introduction to
strftime().Formatting date and time values.
Understanding format codes.
Converting date and time objects into formatted strings.
Introduction to
strptime().Parsing date and time strings.
Converting formatted text into date and time objects.
Applying date and time formatting in Python programs.
Practical example: Format dates for business reports, convert date strings from data files or standardise date formats when processing records from different sources.
Skills You Will Gain
By completing this module, learners will develop the skills to:
Work with Python's date and time functionality.
Create and manage date, time and datetime objects.
Calculate date differences and durations using
timedelta.Extract and manage date and time components.
Perform date-based and time-based calculations.
Work with time zone information.
Handle time zone-aware date and time values.
Format dates and times using
strftime().Convert formatted date strings into date and time objects using
strptime().Process time-based information for scheduling, reporting and business operations.
Develop Python programs that manage dates, durations and time-sensitive tasks.
Learning Outcomes
After completing this module, learners will be able to:
Develop Python programs to manage dates, times and timestamps.
Calculate deadlines, durations and date differences for operational and project-related tasks.
Organise and process time-based information for reporting and record management.
Manage time-based schedules and date-related business conditions.
Handle time zone differences when working with time-sensitive information.
Standardise date formats when processing information from different data sources.
Automate date-related calculations and routine scheduling tasks.
Apply Python date and time functionality to business applications, data processing and workflow automation.
Certification Alignment
This module supports Python date and time concepts relevant to the Python Institute PCAP certification pathway.
Topic Covered | Certification-Relevant Knowledge |
|---|---|
| Date and time types and functionality |
| Duration and date/time calculations |
| Calendar dates and date operations |
| Combined date and time values |
| Time components and operations |
| Time zone information |
Timezone Objects | Time zone offsets and aware datetime values |
| Date and time formatting and parsing |
Continue to the Next Module
Continue to the next module to explore Python database operations and learn how Python interacts with databases to retrieve, manage and process stored information.
Still need help?
Contact us