如何为日期类型数据设置条件

I have table for tasks list.

how can I create condition for dates?

I want to give red color for tasks that their targerDate are in 2 days or less.

    $mainQuery = mysql_query("SELECT * FROM `tasks `");
    while($mainIndex = mysql_fetch_array($mainQuery)) 
{
if ($mainIndex['tagertDate'] <= ???)
}

sql table:

id  int(10) 
title   varchar(250)    utf8_general_ci
targetDate  date    

You can Use PHP's DateTime and Diff function to get the desired result.

Following Function return differnce between current date and provided date in days.

function getDays($date) {
    $datetime1 = new DateTime($date);
    $datetime2 = new DateTime();
    $noOfDays= $datetime1->diff($datetime2);
    return $noOfDays->format('%R%a days');
}

Update:Use a function to compare date like this

Here is check that Say if days returned by getDays($mainIndex['tagertDate']) is less than or eqaul to 2.

if(getDays($mainIndex['tagertDate']) <= 2) {
    Make things colored here
}