I am wanting to insert a Date (as data type of TEXT) in SQLite. This is what I have setup:
def create_table():
c.execute('CREATE TABLE IF NOT EXISTS practice_data(date TEXT, distance REAL, duration REAL, avg_pace REAL)')
date = str(input('Enter DATE (i.e. 2016-01-10): '))
distance = float(input('Enter TOTAL DISTANCE RAN (i.e 2.11): '))
duration = float(input('Enter TOTAL DURATION (i.e. 20.34): '))
avg_pace = float(input('Enter AVERAGE PACE (i.e. 10.44): '))
def data_entry():
c.execute("INSERT INTO practice_data(date,distance,duration,avg_pace) VALUES ({}, {}, {}, {})".format(date, distance, duration, avg_pace))
conn.commit()
c.close()
conn.close()
create_table()
data_entry()
When I run the program it works fine. But when I open the SQLite Browser, the Date Column will not be correct. For example, if I input "2016-11-06" it will enter in "1999". For some reason it is assumming that the ' - ' are subtraction. Even though I have specified that date has a data type of TEXT.
I have seen that SQLite has a datetime option, but I am not sure how to implement it.