Communicating dates and times with another person is pretty simple… right?
“See you at 6 o’clock on Monday” sounds understandable.
But was it a.m. or p.m.? And was your friend in the same time zone as you when you said that? When we need to use and store dates and times on Python, we have the same issues — and even more — since we can express a date and time in many ways. For example:
“July 15, 2019 07:05 pm”
“2019-15-07 19:05:53 CDT”
All of these strings and even the integer expresses the exact same date and time, but they all look very different one from another, right? In this article, we’ll discuss Python datetimes best practices to reduce the complexity when using, formatting, and storing datetimes on a daily basis. Here are the highlights of what we’ll cover:

Python best practices
Creating a Python parser
Creating a Python datetime with a Unix timestamp
Setting the Python datetime time zone
Creating datetime ranges
Getting the current date

To dive deeper into the basic fundamentals of Python, check out Cloud Academy’s new Python for Beginners Learning Path. It’s designed for people new to programming, providing an ideal entry point for people wanting to learn how to program with the Python scripting language. 
Python datetimes best practices
When we talk about a Python datetime format standard, we mean the ISO 8601 (Date and Time Format). This format is used in most of the databases and it has the following structure:
YYYY-MM-DDThh:mm:ss.sss +00:00
YYYY-MM-DDThh:mm:ss.sss TZ
But when we show it to the user, we might want to change the way it looks. This is because if we use a tool to get it from the user — like a calendar or select inputs — it can also vary on the way the data is sent to the backend.
Creating a Python parser
Luckily, Python has a parser that understands pretty much

View Entire Article on