1

This is what I have made:

#!C:\Users\matej\PycharmProjects\SupremeBot\venv\Scripts\python.exe

import datetime
import webbrowser


#ADDING "SHOW WHEN THE BOT STARTS FUNCTION"

itstime = datetime.time(12, 0,)
now = datetime.datetime.today()


print("This is time when the program was started.:")
print(now)
print("This is when it is time to cop!!:")
print(itstime)





#BOT WEB OPEN FUNCTIONALITY"



if now < itstime:
    pass


if now == itstime:
    webbrowser.open("http://www.supremenewyork.com")

I am now currently having issues with time:

C:\Users\matej\PycharmProjects\SupremeBot\venv\Scripts\python.exe C:/Users/matej/PycharmProjects/SupremeBot/SupremeBot.py
This is time when the program was started.:
2020-04-03 21:11:03.697831
This is when it is time to cop!!:
12:00:00
Traceback (most recent call last):
  File "C:/Users/matej/PycharmProjects/SupremeBot/SupremeBot.py", line 26, in <module>
    if now < itstime:
TypeError: '<' not supported between instances of 'datetime.datetime' and 'datetime.time'

Process finished with exit code 1

How to solve this? Any ideas how to make it better, faster or just more stable? I would be thankful for any responds.

thafuga
  • 15
  • 3

1 Answers1

0

The problem is that you're comparing a "full" date stamp to a timestamp, which doesn't make sense. Think about it this way: which is greater: Tuesday, March 1, 2020 at 12:30 PM, or 12:40 PM? This doesn't exactly make sense.

This line:

TypeError: '<' not supported between instances of 'datetime.datetime' and 'datetime.time'

is telling you that you're comparing objects of different type.

It does, however, make perfect sense to compare 12:30 PM to 12:40 PM - so basically, only compare the timestamps. If you want to compare only the time portion of the date, see the Q&A below to get only the time portion of the date stamp:

Python: Converting from `datetime.datetime` to `time.time`