0

如果列中的一个日期是当前日期,我想从 mysql 中搜索一个数组。例如,我在数组中有这个日期:

2013-09-03,2013-09-04,2013-09-06,2013-09-05,2013-09-07 

和当前日期:2013-09-03 所以我试试这个:

$dates = unserialize($row['dates']);
$currentDate = date("Y-m-d");

$array = array($dates);
if (in_array($currentDate, $array)) {
echo "IS HERE !";
}

但没有运气。

4

2 回答 2

1

你说var_dump($row["dates"])的结果是:

array(1) { [0]=> string(54) "2013-09-03,2013-09-04,2013-09-06,2013-09-05,2013-09-07" }

含义$row["dates"][0]包含所有日期的字符串。

你可以这样做来测试:"

$currentDate = date("Y-m-d");

$date_array = explode(',', $row["dates"][0]); // Create an array with all your dates

if (in_array($currentDate, $date_array)) {
    echo "IS HERE !";
}

你也可以这样做:

// Because $row["dates"][0] is a string with dates, you can simply search the date as string.
if(strpos($row["dates"][0], $currentDate) !== FALSE){
    echo "IS HERE !";
}
于 2013-09-06T09:12:42.480 回答
-2

仅获取具有今天日期的行怎么样?

SELECT * FROM myTable WHERE DATE(myDate) = DATE(NOW())
于 2013-09-03T13:43:49.553 回答