简体   繁体   English

日期与strtotime无法正常工作-PHP

[英]date with strtotime not working properly - php

I can't get this date with strtotime function to work properly. 我无法使用strtotime函数使此日期正常运行。 I need to convert the date to display to "d/m/Y". 我需要将日期转换为“ d / m / Y”。 I'm getting the date off the database correctly but it does not convert to my new date format, instead it just echoes everything with the date inside the $row[saleDate]. 我从数据库中正确获取了日期,但是它没有转换为新的日期格式,而是仅在$ row [saleDate]中回显带有日期的所有内容。

Here's the code: 这是代码:

    echo "<tr><td class='contentTd'> $row[saleNumber] </td>
            <td class='contentTd'> $row[saleValue] </td>
            <td class='contentTd'> $row[paymentMethod] </td>
            <td class='contentTd'> $row[sellerName] </td>
            <td class='contentTd'> date('d/m/Y', strtotime($row[saleDate])); 
            </td></tr>";

Could you help me out please? 你能帮我一下吗?

Use concatenation to show the date.. 使用串联显示日期。

      echo "<tr><td class='contentTd'> $row[saleNumber] </td>
        <td class='contentTd'> $row[saleValue] </td>
        <td class='contentTd'> $row[paymentMethod] </td>
        <td class='contentTd'> $row[sellerName] </td>
        <td class='contentTd'>".' date('d/m/Y', strtotime($row[saleDate]);'. 
        "</td></tr>";

我认为您忘记了date()函数或strtotime()函数

I've found the error: Missing quotes inside the strtotime function. 我发现了错误:strtotime函数内缺少引号。

echo "<tr><td class='contentTd'> $row[saleNumber] </td>
            <td class='contentTd'> $row[saleValue] </td>
            <td class='contentTd'> $row[paymentMethod] </td>
            <td class='contentTd'> $row[sellerName] </td>
            <td class='contentTd'>" . date('d/m/Y', strtotime("$row[saleDate]")) . "</td></tr>";

Now it's working fine! 现在一切正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM