Subscribe Contact

Home  »  Chapter 2 : Programming Basics
Dates & Times


Overview

There are many circumstances in programming that require working with dates and times. Working with data types like integers, floats, and strings is straight forward as we saw on the previous pages in this book. Dates and times are a bit different because they are not simply numbers or strings, they embody more complicated concepts like different date formats, for example 05/01/2023, 2023-05-01, May 1, 2023 all indicate the same date. Also, formats are different in different countries, for example the standard format in the United States is month/day/year, while some other countries format their dates day/month/year. In addition, we also have to take into account daylight savings time, leap years, and different timezones, as well. To complicate things even more, we often need to calculate spans time between dates and time ranges, setting alarms and scheduling processes, all of which depend on programmatically determining how much time has passed or when a particular date/time has arrived.

All of these requirements can seem overwhelming at first, but fortunately Python provides libraries that help programmers handle all of these tasks. In this section, we will explore these concepts using several tools found in Python.


Date & Time Data

Dates 05/01/2023, 2023-05-01, May 1, 2023

The datetime Library

Title



 


«  Previous : User Input
Next : Basic Operators  »




© 2023 John Gordon
Cascade Street Publishing, LLC