Mysql – How to select records where NOW is between two dates in fields

MySQLPHP

I've searched all over for this, and I seem only to find how to get records where a single date is between two "outside" dates.

I want to find out how to select records where the current date is between the value in the startDate field and the value in the endDate field.

What I have so far (PHP):

$now = new DateTime();
$sql = "
    SELECT content, image, imageHeight, imageWidth, link, linkDescription 
    FROM news 
    WHERE appearanceDate < $now  
      AND $now < termDate 
    ORDER BY appearanceDate DESC
";

But it doesn't work.

Best Answer

You can use the NOW() function in . Note, this assumes that termDate is the later date:

Select content, image, imageHeight, imageWidth, link, linkDescription
  From news
  Where appearanceDate < NOW() 
    And termDate > NOW()
  Order By appearanceDate Desc;