Compare Two Dates

Take two dates (day and month) and determine which one comes first.

Logic BuildingAdvanced
Logic Building
# Take first date
day1 = int(input("Enter first day: "))
month1 = int(input("Enter first month: "))

# Take second date
day2 = int(input("Enter second day: "))
month2 = int(input("Enter second month: "))

# Compare dates
if month1 < month2:
    print("First date comes earlier")
elif month1 > month2:
    print("Second date comes earlier")
else:  # Same month
    if day1 < day2:
        print("First date comes earlier")
    elif day1 > day2:
        print("Second date comes earlier")
    else:
        print("Same date")

Output

Enter first day: 15
Enter first month: 3
Enter second day: 20
Enter second month: 3
First date comes earlier

Enter first day: 15
Enter first month: 3
Enter second day: 10
Enter second month: 4
First date comes earlier

Compare months first, then days if months are same.

Key Concepts:

  • Compare months first
  • If months equal, compare days
  • Handle all cases: earlier, later, same