Attributes of a Date in Python – Complete Guide for Data Science 2026
Understanding the attributes of Python’s date object is fundamental for effective date-based feature engineering, reporting, and time-series analysis. The date class provides direct, efficient access to year, month, day, weekday, and other calendar properties without the complexity of full datetime objects.
TL;DR — Key Attributes & Methods
.year,.month,.day→ core calendar components.weekday()and.isoweekday()→ weekday information.strftime()→ flexible string formatting.isoformat()→ standard ISO string representation
1. Basic Date Attributes
from datetime import date
d = date(2026, 3, 19)
print(f"Year: {d.year}")
print(f"Month: {d.month} ({d.strftime('%B')})")
print(f"Day: {d.day}")
print(f"Weekday number (0=Monday): {d.weekday()}")
print(f"ISO Weekday (1=Monday): {d.isoweekday()}")
print(f"Day name: {d.strftime('%A')}")
2. Real-World Data Science Usage with pandas
import pandas as pd
df = pd.read_csv("sales_data.csv", parse_dates=["order_date"])
# Extract date attributes efficiently
df["order_year"] = df["order_date"].dt.year
df["order_month"] = df["order_date"].dt.month
df["order_day"] = df["order_date"].dt.day
df["order_weekday"] = df["order_date"].dt.weekday
df["order_day_name"] = df["order_date"].dt.day_name()
df["order_quarter"] = df["order_date"].dt.quarter
print(df[["order_date", "order_year", "order_month", "order_day_name"]].head())
3. Formatting and String Conversion
d = date.today()
print(d.isoformat()) # 2026-03-19
print(d.strftime("%Y-%m-%d")) # 2026-03-19
print(d.strftime("%A, %B %d, %Y")) # Thursday, March 19, 2026
print(d.strftime("%d/%m/%Y")) # 19/03/2026
4. Best Practices in 2026
- Use pandas
.dtaccessor for vectorized extraction on large DataFrames - Prefer
dateobjects when you only need the date part (no time component) - Always work with timezone-aware
datetimeobjects and convert to.date()when needed - Use
strftime()for human-readable reports and logging - Store original datetime columns and derived date attributes separately for flexibility
Conclusion
The attributes of a date object in Python provide clean, direct access to all essential calendar information. In data science, these attributes are heavily used for feature engineering, seasonality analysis, reporting, and building time-based insights. Combine Python’s date class with pandas .dt accessor to process large datasets efficiently and create powerful date-derived features.
Next steps:
- Open one of your datasets containing datetime columns and explore its date attributes to create new time-based features