syam deth
syam deth

Reputation: 231

comparing two fields in mysql

is their any query to pick certain date between two time stamps?The Problem is these two times stamps are set in two diffrent fieldsenter image description here

Upvotes: 0

Views: 70

Answers (4)

SMA
SMA

Reputation: 37093

Try this:

SELECT * 
FROM table 
WHERE fs_from > 'some date' 
AND   fs_to <  'some other date'

Upvotes: 1

Gianluca Colombo
Gianluca Colombo

Reputation: 829

In my opinion you can try in this way (If I really understood your question)

SELECT myFields FROM myTable 
     WHERE myCertainDate BETWEEN fs_from AND fs_to

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1271003

Which date do you want? You can choose a random date by doing:

select t.*,
       date_add(t.fs_from, interval cast(datediff(fs_to, fs_from) * rand() as int) day
               ) as ArbitraryDateBetweenTwoDates
from table t

Upvotes: 0

Aviator
Aviator

Reputation: 522

SELECT * FROM table WHERE fs_from > theDate AND fs_to < theDate;

I suggest to use prepared statements and insert a date object into the query.

Upvotes: 1

Related Questions