pythonsqlite3-python

How to select unique date from datetime column in sqlite3 python


This is how DB looks like

I want to get only dates without any time like: [('2023-07-28',), ('2023-07-29',), ...]

I've already tried: CURSOR.execute(f"SELECT strftime('%Y-%m-%d', date) FROM {name}_schedule WHERE strftime('%Y-%m-%d', date) >= DATE('now') LIMIT(6) OFFSET({count})")

But i got dates with time: [('2023-07-28',), ('2023-07-28',), ('2023-07-28',), ('2023-07-29',), ('2023-07-29',), ('2023-07-29',)]


Solution

  • CURSOR.execute(f"SELECT DISTINCT strftime('%Y-%m-%d', date) FROM {name}_schedule WHERE strftime('%Y-%m-%d', date) >= DATE('now') LIMIT(6) OFFSET({count})")
    

    DISINCT choosing only unique values, so the problem solved