Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

sql - Select all rows between two specific times across multiple days

I'm managing an SQLite database containing messages along with associated timestamps collected over the past month, and I wish to select all of the entries, for all days, between two given hours. In pseudocode style: SELECT * FROM Messages BETWEEN x AND y, where x might be 14:45 and y 15:45, and returning all the messages between x and y for all the days over the past month.

Is there a straightforward way of performing this in SQLite?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you are looking for something like this:

SELECT *
FROM MESSAGES
WHERE time(timestamp) >= time('14:45:00')
  AND time(timestamp) <= time('15:45:00')

Fiddle: http://sqlfiddle.com/#!9/cde2c/1/0

I took information from: http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...