-2

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',)]

PR. OR
  • 1
  • 2
  • 1
    The output in the last paragraph doesn't contain times. – Michael Butscher Jul 28 '23 at 18:27
  • You SPECIFICALLY asked it for only the date (`strftime('%Y-%m-%d',date)`). If you want the whole date, then just do `SELECT date`. That will create Python datetime objects, and you can format those however you want. Also, can't you just do `WHERE date >= now`? Why do you insist on converting to strings? SQL handles dates and times very competently. – Tim Roberts Jul 28 '23 at 18:27
  • These dates are identical, three times 28th of July three times 29th of July I want [('2023-07-28',), ('2023-07-29',), ...] – PR. OR Jul 28 '23 at 18:28
  • 1
    So, are you saying you only want one record for each date? Why didn't you say that? `SELECT UNIQUEROW` will do that. – Tim Roberts Jul 28 '23 at 18:29
  • UNIQUEROW causes an error: sqlite3.OperationalError: near "(": syntax error / CURSOR.execute(f"SELECT UNIQUEROW strftime('%Y-%m-%d', date) FROM {name}_schedule WHERE strftime('%Y-%m-%d', date) >= DATE('now') LIMIT(6) OFFSET({count})") – PR. OR Jul 28 '23 at 18:31
  • 2
    If only want unique dates then try `SELECT DISTINCT(strftime('%Y-%m-%d', date)) ...` – CodeMonkey Jul 28 '23 at 18:42

1 Answers1

0
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

PR. OR
  • 1
  • 2