Dates without drama — Python’s datetime made simple


Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python.

Today, we’ll explore the datetime module — the fastest way to work with dates and timestamps in Python

What is datetime module?

A built-in Python library that supplies classes for dealing with dates & times.

🛞 Create, manipulate, and format date and time values.

❓ Why it matters - Think of last 3 month, 6 month sales tracking; invoice generation dates, or scheduling reminders - datetime is the tool to handle all those in code.

Get today's date

In:
from datetime import date
d = date.today()
print(d)
Out:
2025-08-22

Get current date and time

In:
from datetime import datetime
now = datetime.now()
print(now)
Out:
2025-08-22 13:20:00

💡 Did you notice we imported datetime from datetime? First one is a module, 2nd one is a class! Simple but important concept (read more)

⭐ Split date into year, month & day

In:
from datetime import date
d = date.today()
print(d.year, d.month, d.day)
Out:
2025 8 22

⭐ Create specific date

In:
from datetime import date
deadline = date(2025, 9, 30)
print(deadline)
Out:
2025-09-30

⭐ Create specific datetime

In:
from datetime import datetime
meeting = datetime(2025, 9, 30, 18, 0, 0)
print(meeting)
Out:
2025-09-30 18:00:00

⭐ "strftime" to format as per your need

In:
from datetime import date
d = date(2025, 8, 22)
print(d.strftime("%d-%m-%Y"))
print(d.strftime("%d %b %Y"))
print(d.strftime("%A"))
Out:
22-08-2025
22 Aug 2025
Friday

⭐ "Week" and "Weekday"

Given date is 34th week and 5th weekday

In:
from datetime import date
d = date(2025, 8, 22)
print(d.isocalendar())
Out:
(2025, 34, 5)

⭐📣 That was the intro, lot more on datetime coming up on Monday. If you liked it, please share it with anyone who will find it useful and share your feedback below 🐼

Pandas Daily

Beginner to Expert in Python in just 5 minutes

Read more from Pandas Daily

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Today: Lets dive right away into some of the applications and advanced functions of "math" module. Do check out last two issues for a refresher. 📝 Sum of all numbers in a list? In: import math amounts = [50.12, 25.35, 14.53] total = math.fsum(amounts) print(total) Out: 90.0 🚀🚀 Multiply all numbers of list in one go! In: print(math.prod([2, 2, 3])) Out: 12 📍 Distance between two points (latitude, longitude...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Today is the 2nd day of Python’s math module where we go one level deep! You might go into memory lane as some concepts we would have studied during high school. Feel free to go through first part real quick. 📐 Remember Pythagoras's Theorem? Calculate hypotenuse from two shorter sides In: import math print(math.hypot(3, 4)) Out: 5.0 🌟 Taking logarithms in variety of ways In: print(math.log(100)) # natural...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Today, we'll introduce Python’s math module—your shortcuts for real calculations. What is the math Module? A standard Python library that provides mathematical functions - square root, logarithm, trigonometry, you name it. Tasks from rounding prices for invoices to complex analytics for finance or science can be done in a breeze. Why it matters? You’ll use it for rounding numbers, growth projections,...