coder188642
coder188642

Reputation: 145

TypeError: '>' not supported between instances of 'int' and 'str'

I am writing code to have inputs for a date (day month and year) and how many times they want to repeat the task (what its for.) I want to use a for loop using times as the boundaries. Code:

def addtimeslot():
    times = int(times_repeated.get())
    print(times_repeated.get())
    variable_end.get()
    day = variable_day.get()
    month = variable_month.get()
    year = variable_year.get()
    fulldateadd = datetime.date(year, month, day)
    name1 = str(name.get())
    minute = int('00')
    second = int('00')
    hour1 = variable_st.get()
    starttimehour = str(datetime.time(hour1,minute,second))
    hour2 = variable_end.get()
    endtimehour = str(datetime.time(hour2,minute,second))
    for i in range(0 , times):
        fulldateadd = datetime.date(year, month, day)
        cursor.execute( '''INSERT INTO dates (Date, Name, Start, End) VALUES( ?,?,?,? );''', (fulldateadd , name1, starttimehour, endtimehour))
        day = int(day) + 7
        if day > '31':
            month = int(month) + 1

I get this error:

TypeError: '>' not supported between instances of 'int' and 'str' 

Upvotes: 2

Views: 18782

Answers (1)

Sebastian Walla
Sebastian Walla

Reputation: 1124

As questions shouldn't be answered in the comments I'll provide the solving comment of @AChampion:

You've made day an int with day = int(day) + 7 so the test should be if day > 31:, i.e. a comparison to an int 31 not a string '31'

Upvotes: 3

Related Questions