简体   繁体   中英

Select Rows Between Start and End Column (Unix timestamps)

I'm trying to write a query that takes a Unix Timestamp (ie 1396396810 = 4/1/2014 6:00:10 PM) and check a table to see if that date falls between the start and end columns.

1396332000 = 4/1/2014 12:00:00 AM

1396504800 = 4/3/2014 12:00:00 AM

I have table deposit_dates

id | start | end | status
--------------------------
1  | 1396332000 | 1396504800 | 1

And I have a query

SELECT * FROM deposit_dates
WHERE start >= 1396396810
AND end <= 1396396810;

My problem is that the query returns 0 rows, when 1396396810 is between 1396332000 and 1396504800 .

Thank you in advance!

your query needs to be

SELECT * FROM deposit_dates
WHERE start <= 1396396810
AND end >= 1396396810;

Try below query

SELECT * FROM deposit_dates WHERE timestamp BETWEEN start AND end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM