haroon amjad haroon amjad - 7 months ago 9
PHP Question

PHP mySQL, how to get data from mysql for today ranging between 2 dates

I have two columns in my

MySQL
table,
valid_from
&
valid_till
both have dates in them.

I want to get the record for today's date like for example if today is 2016-04-22, and there is a record in my table which has valid_from & valid_till dates and today's date falls within the range of that record, then I want that record.

My question is how can I do that? Thank you!

The image of my table:

enter image description here

Answer

This way you test if the date, for example today's date, id between valid_from date and valid_till date:

select * from (table_name) 
where (date_to_test) > valid_from and (date_to_test) < valid_till;
Comments