Working with dates is a common task in Python programming. Whether you're building a web application, processing data, or generating reports, you'll often need to format dates in specific ways. This guide covers the most common date formatting patterns with practical examples you can use in your projects. If you need a quick way to format dates without writing code, try this Date & Time Formatter tool.
Getting Started with Python's datetime Module
First, let's import the necessary module datetime and create a sample date to work with throughout our examples:
from datetime import datetime
# Create a sample date for our examples
sample_date = datetime(2025, 12, 1, 19, 30, 16)
print(f"Original date: {sample_date}") Code result as follows:

Common Date Formatting Patterns
Python uses the strftime() method to format dates. The method takes a format string with special codes that represent different parts of the date. Here are the most useful formatting patterns:
Full Date with Day Name
formatted = sample_date.strftime('%A, %B %d, %Y, %I:%M:%S %p')
print(formatted) Month and Day with Year
formatted = sample_date.strftime('%B %d, %Y')
print(formatted) Month with Ordinal Day
Note: Python's standard library doesn't directly support ordinal indicators (st, nd, rd, th). We need a helper function:
from datetime import datetime
def get_ordinal(n):
if 10 <= n % 100 <= 20:
suffix = 'th'
else:
suffix = {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')
return f"{n}{suffix}"
sample_date = datetime(2025, 12, 1, 19, 30, 16)
day_with_ordinal = get_ordinal(sample_date.day)
formatted = f"{sample_date.strftime('%B')} {day_with_ordinal} {sample_date.year}"
print(formatted) Output 
Day First with Month and Year
day_with_ordinal = get_ordinal(sample_date.day)
formatted = f"{day_with_ordinal} {sample_date.strftime('%B')} {sample_date.year}"
print(formatted) Full Date with Time (Ordinal Day)
day_with_ordinal = get_ordinal(sample_date.day)
formatted = f"{sample_date.strftime('%B')} {day_with_ordinal} {sample_date.year}, {sample_date.strftime('%I:%M:%S %p').lstrip('0')}"
print(formatted) Day Name First Format
formatted = sample_date.strftime('%A, %d %B %Y, %I:%M:%S %p')
print(formatted) Compact Format with 24-Hour Time
formatted = sample_date.strftime('%a, %d %b %Y %H:%M:%S PM')
print(formatted) Numeric Formats
formatted = sample_date.strftime('%m/%d/%Y')
print(formatted) formatted = sample_date.strftime('%Y-%m-%d')
print(formatted) Abbreviated Month Format
formatted = sample_date.strftime('%b %d, %Y')
print(formatted) ISO Format with Timezone
# For timezone-aware formatting, we need to use timezone information
from datetime import timezone, timedelta
# Create a timezone-aware datetime (UTC+8 as an example)
tz = timezone(timedelta(hours=8))
aware_date = sample_date.replace(tzinfo=tz)
formatted = aware_date.isoformat()
print(formatted) Complete Reference of Format Codes
Here's a quick reference of the most commonly used format codes in Python's strftime method:
%a - Weekday as abbreviated name (Sun, Mon, etc.)
%A - Weekday as full name (Sunday, Monday, etc.)
%d - Day of the month as zero-padded decimal (01 to 31)
%m - Month as zero-padded decimal (01 to 12)
%b - Month as abbreviated name (Jan, Feb, etc.)
%B - Month as full name (January, February, etc.)
%y - Year without century as zero-padded decimal (00 to 99)
%Y - Year with century as decimal (2025)
%H - Hour (24-hour clock) as zero-padded decimal (00 to 23)
%I - Hour (12-hour clock) as zero-padded decimal (01 to 12)
%p - Locale's equivalent of either AM or PM
%M - Minute as zero-padded decimal (00 to 59)
%S - Second as zero-padded decimal (00 to 59) Putting It All Together
Here's a complete example that demonstrates multiple formatting options in one script:
from datetime import datetime
def format_date_examples():
# Create our sample date
date_obj = datetime(2025, 12, 1, 19, 30, 16)
# Define various format patterns
formats = [
('%A, %B %d, %Y, %I:%M:%S %p', 'Full date with day name'),
('%B %d, %Y', 'Month and day with year'),
('%m/%d/%Y', 'Numeric US format'),
('%Y-%m-%d', 'ISO date format'),
('%b %d, %Y', 'Abbreviated month format'),
('%a, %d %b %Y %H:%M:%S', 'Compact format with 24-hour time')
]
# Apply each format and print results
for fmt, description in formats:
formatted = date_obj.strftime(fmt)
print(f"{description}: {formatted}")
if __name__ == "__main__":
format_date_examples() Output

Conclusion
Python's datetime module provides powerful tools for working with dates and times. The strftime method is particularly useful for formatting dates according to specific patterns. With the examples in this guide, you should be able to handle most date formatting requirements in your Python projects.
Remember that date formatting can be locale-specific. If you're building applications for international audiences, you might need to consider localization aspects beyond what's covered here.