🐍 Pythons learning
PYTHON • DATA SCIENCE • AI

Master Python, Data Science & Machine Learning

#Python #Pandas #NumPy #MachineLearning #Projects

Monday, November 23, 2026

Datetime Module in Python: Handling Dates and Times

The datetime module supplies classes for manipulating dates and times in Python. It supports date and time arithmetic, formatting, parsing, and time zone management.


Installation:

Built-in module (No installation required)


Key Features:

- Work with dates (date), times (time), and combined date-time (datetime)

- Measure time spans and intervals using timedelta

- Format dates to strings (strftime) and parse strings to dates (strptime)

- Time zone aware calculations with timezone


Code Example:

from datetime import datetime, timedelta


# Get current date and time

now = datetime.now()

print("Current DateTime:", now.strftime("%Y-%m-%d %H:%M:%S"))


# Add 7 days to current date

future_date = now + timedelta(days=7)

print("Date in 7 days:", future_date.strftime("%Y-%m-%d"))

No comments:

JSON Module in Python: Parsing and Writing JSON Data

The json module in Python allows you to encode and decode JSON (JavaScript Object Notation) data. It provides built-in methods for convertin...