如何从数据库转换字符串日期?

时间:2018-07-17 14:12:40

标签: php mysql mysqli

我有一个来自MySQL数据库的字符串日期“ July 14, 2018”。我只想将其转换为date格式,因为我认为查询无法识别它。我的代码如下:

$res=mysqli_query($conn,"SELECT SUM(price) as INCOME,DATE_FORMAT('%Y-%m',trans_date) as Date
                        from transactions where status='Paid' 
                        GROUP BY DATE_FORMAT('%Y-%m', trans_date)");

while($row=mysqli_fetch_array($res))
{
    $income = $row['INCOME'];
    $date = $row['Date'];

    $formattedincome = number_format($income, 2)."<br>";
    echo "₱".$formattedincome;
    echo $date;
}

当我尝试在phpmyadmin上运行查询时,Date列为NULL

enter image description here

希望有可能。预先谢谢你。

0 个答案:

没有答案