Lee Salminen
Lee Salminen

Reputation: 880

Select Rows Between Start and End Column (Unix timestamps)

I'm trying to write a query that takes a Unix Timestamp (i.e. 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!

Upvotes: 0

Views: 217

Answers (2)

Ayyappa Boligala
Ayyappa Boligala

Reputation: 1096

Try below query

SELECT * FROM deposit_dates WHERE timestamp BETWEEN start AND end;

Upvotes: 0

Raja Nadar
Raja Nadar

Reputation: 9489

your query needs to be

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

Upvotes: 3

Related Questions