Python Tip of the Day: Handle Dates and Times with datetime

Handle Dates and Times with datetime

Author: Jeremy Morgan
Published: November 29, 2024


Coding with AI

AI changed software development. This is how the pros use it.

Written for working developers, Coding with AI goes beyond hype to show how AI fits into real production workflows. Learn how to integrate AI into Python projects, avoid hallucinations, refactor safely, generate tests and docs, and reclaim hours of development time—using techniques tested in real-world projects.

See What's Inside

Working with dates and times? The datetime module has everything you need.

# Get current date and time
from datetime import datetime

now = datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M:%S")
print(f"Current time: {formatted_time}")
# Output: Current time: 2023-10-30 12:34:56

“Python Tip of the Day: Handle Dates and Times with datetime”


The Python Tip of the Day is a daily series published in the month of November. The tips are designed to help you become a better Python programmer. I post tips like this and more every single day on X. Let’s connect!


Coding with AI

AI changed software development. This is how the pros use it.

Written for working developers, Coding with AI goes beyond hype to show how AI fits into real production workflows. Learn how to integrate AI into Python projects, avoid hallucinations, refactor safely, generate tests and docs, and reclaim hours of development time—using techniques tested in real-world projects.

See What's Inside