While循环中的PHP Day (l)没有显示正确的日期


PHP Day (l) in While Loop not showing proper day

我从数据库中获取数据并显示在表中。获取工作正常的所选日期范围之间的日期。

while ($row = mysql_fetch_array($query)) {
 $date = $row['tt_date']; //get dates from table column
echo $date; // showing proper values
}

当我添加

echo date('l', strtotime( $date)); 

 echo date('l',$date);

一直显示Thursday对于所有从表中检索数据;

应该显示检索日期的正确日期

根据OP的注释,似乎$date变量包含多个日期,因此OP需要爆炸该字符串,并在循环中将.字符更改为-:

    $date = '2015.08.31 | 2015.08.31 | 2015.09.02';
    echo $date;
    //Will output 2015.08.31 | 2015.08.31 | 2015.09.02
    //So now here, you need to explode this string with " | "
    $datesArray = explode(" | ", $date);
    var_dump($datesArray);
    //The output is:
    //array (size=3)
    //  0 => string '2015.08.31' (length=10)
    //  1 => string '2015.08.31' (length=10)
    //  2 => string '2015.09.02' (length=10)
    //Now you need to iterate through on this array
    foreach ($datesArray as $dateString) {
        //You need to replace the "." character to "-" for the strtotime function
        echo date('l', strtotime( str_replace('.','-',$dateString))) ."<br>'n";
    }
    //Output is:
    //Monday
    //Monday
    //Wednesday
    //I've checked the calendar, and it's correct