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!

1 Answer 1

3

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])
Sign up to request clarification or add additional context in comments.

1 Comment

you could also write the query like SELECT strftime('%Y-%m-%d', due), ...

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.