B
B
B1ackGh0st2016-03-24 04:37:57
Python
B1ackGh0st, 2016-03-24 04:37:57

How to select a record from SQLite with the most appropriate time?

Hello.
The table has 2 columns with time one with unuxtime the other looks like ymd h:m:s
All records in the table with an interval of 3 hours.
2016-03-24 06:00:00
2016-03-24 09:00:00
2016-03-24 12:00:00
How do I select the most "recent" entry in time. for example, if now is 2016-03-24 10:25 then select the record with the time 2016-03-24 09:00:00. DB sqlite
I hope the question was formulated clearly

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2016-03-24
@B1ackGh0st

SELECT * FROM yourtable 
WHERE 
unuxtime_column <=  strftime('%s', 'now', 'localtime')
ORDER BY unuxtime_column DESC LIMIT 1;

Something like this, if I understand the question correctly.

A
Alexander, 2016-03-24
@bIbI4k0

Is unixtime an integer? Then you can do this:
If there is an auto increment,
or

SELECT * FROM tablename WHERE id = (SELECT MAX(id) FROM tablename);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question