views:

44

answers:

1

I use a simple SQL query in Python to grab records from a SQLite 3 database:

cursor.execute ("SELECT due, task FROM tasks WHERE due <> '' ORDER BY due ASC")
        rows = cursor.fetchall()
            for row in rows:
                print '\n%s %s' % (row[0], row[1])

The due field in the database is set to DATE type, so the query returns the data in this field formatted as 2010-07-20 00:00:00.00 How can I remove the 00:00:00.00, so the result contains only the date? Thanks!

+3  A: 

I think row[0] is a datetime object. So the following should work:

print '\n%s %s' % (row[0].strftime('%Y-%m-%d'), row[1])
DiggyF
Works like a charm. :-) Thanks!
you could also write the query like `SELECT strftime('%Y-%m-%d', due), ...`
Nick D