php错误的日期格式

时间:2011-11-14 00:03:51

标签: php mysql date

我有这个购物车,它将订单发送到mysql数据库以及订购时的日期:日期的代码如下:

<?
    include("includes/db.php");
    include("includes/functions.php");  

    $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=$_SESSION['cart'][$i]['qty'];
            $price=get_price($pid);
            $date=date('Y/m/d');
            $user=$_SESSION['username'];
            $pname=get_product_name($pid);
            mysql_query("insert into `order` values ('','$pname','$q','$price','$date','$user')")

                or die(mysql_error());

它输出日期为2011 / 11,14。我如何得到它输出如下:14/11/2011 ??

2 个答案:

答案 0 :(得分:1)

问题在于$date = date...行。我不打算直接回答你的问题,但请看看the documentation for date()对于初学者。此外,您应该使用DATE数据库字段而不是字符串来存储

答案 1 :(得分:0)

更改此行:

date('Y/m/d');

date('d/m/Y');
相关问题