Home > Back-end >  From date.today() to datetime for greater or less than another datetime python
From date.today() to datetime for greater or less than another datetime python

Time:06-14

When I try to run the following code, python returns an error. I think this is because date.today() isn't in the datetime format.

R_timer=2021-12-07 00:00:00 (in datetime format)
if date.today()>=R_timer:
    print('1')

Python returns: Comparison of Timestamp with datetime.date is deprecated in order to match the standard library behavior. In a future version these will be considered non-comparable. Use 'ts == pd.Timestamp(date)' or 'ts.date() == date' instead.

CodePudding user response:

The problem is R_timer is of type datetime.datetime, and date.today() is of type datetime.date. Instead, try:

from datetime import datetime
if datetime.today() >= R_timer:
    print('1')

CodePudding user response:

from datetime import datetime 
R_timer = datetime(2021, 12, 7, 0, 0, 0)
if datetime.today()>=R_timer:
    print('1')
  • Related