SQLite Select next date time in future

Viewed 35

Hi I have date time entries like

  1. 2022-09-16 12:31:27

  2. 2022-09-16 13:31:27

  3. 2022-09-16 14:31:27

  4. 2022-09-16 15:31:27

Where the current time is I want to select the next entry in the future. ie if the current time is 2022-09-16 14:20:04 I want to select 3.

I think I need the NOW command but I'm not sure and it is not working.

SELECT * FROM tasks ORDER BY date(NOW) DESC LIMIT 1
1 Answers

I believe that you want a query such as:-

SELECT * FROM tasks WHERE date > datetime('now') ORDER BY date LIMIT 1;
Related