Source Code:
(back to article)
from datetime import datetime, timedelta # Parse the start and end dates start_date = datetime.strptime("2022-01-01", "%Y-%m-%d") end_date = datetime.strptime("2022-01-31", "%Y-%m-%d") # Calculate the number of days between the two dates num_days = (end_date - start_date).days print(num_days) # prints 30
Result:
Report an issue