0

I am writing code that will add staff shifts into a shift schedule. the part I am trying to get to work is one that adds shifts in that recur every week (ie work every Monday at 5). I thought I had a good way of doing it until I started getting error messages regarding the datatype. I am new to the datetime module so I apologise if there is a simple explanation

here is the relevant part of my code:

def addWeekly(STAFFID,SDAY,SMONTH,SYEAR,STARTTIME,ENDTIME):
    DATE = datetime.date(SYEAR, SMONTH, SDAY)
    conn = sqlite3.connect('test.db')
    cursor = conn.cursor()
    count = 0

    for records in cursor:
        count += 1
    SHIFTID = count

    for i in range(100):
        cursor.execute('INSERT INTO SHIFT VALUES (?,?,?,?,?)',
            (SHIFTID,STAFFID,DATE,STARTTIME,ENDTIME))
        DATE += timedelta(days=7)

and here is the error:

Traceback (most recent call last):
  File "C:/Users/360491/Documents/Coursework/Prototypes/calendar fix.py", line 36, in <module>
addWeekly(STAFFID,SDAY,SMONTH,SYEAR,STARTTIME,ENDTIME)
  File "C:/Users/360491/Documents/Coursework/Prototypes/calendar fix.py", line 16, in addWeekly
DATE = datetime.date(SYEAR, SMONTH, SDAY)
TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'str'

i have tried using integers. any help would be greatly appreciated

3
  • Are you sure SYEAR, SMONTH, SDAY are integers? Commented Sep 15, 2017 at 13:52
  • Can you show your imports? Commented Sep 15, 2017 at 13:56
  • When you get the answer you need on SO you should, please, mark it 'accepted'. With sufficient reputation you can start up-voting answers. Commented Sep 15, 2017 at 20:44

1 Answer 1

1

Are you importing datetime.datetime?

Try just using import datetime

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.