Home > Software design >  How to use datetime library to compare dates?
How to use datetime library to compare dates?

Time:02-16

how can I check inside Python if the first date is bigger than the second date or not?

DATA 1 : "2022-2-15" DATA 2 : "2022-2-16"

CodePudding user response:

Use the datetime library :

from datetime import datetime

date1 = datetime(2022, 2, 15)
date2 = datetime(2022, 2, 16)

Then you can use standard comparison operators (>, <, ...)

CodePudding user response:

This code is correct

from datetime import datetime

date1 = datetime(2022,2,15)
date2 = datetime(2022,2,16)

print(date1 >  date2) # False
  • Related