Convert date to timestamp and timestamp to date in Python

From PedrosBrainDump

Date to timestamp

from datetime import datetime

# Date
date = datetime(2025, 2, 6)  # Example date (Year, Month, Day)

# Convert to timestamp
timestamp = date.timestamp()

print(timestamp)

Timestamp to date

from datetime import datetime

# Timestamp
timestamp = 1615931732  # Example timestamp 

# Convert to date
date = datetime.utcfromtimestamp(timestamp).date() 

print(date)