Jahed
Jahed

Reputation: 75

php wrong date format

i have this shopping cart in which it sends the orders to mysql database along with the date on when it was ordered: the code for the date is as follows:

<?
    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());

it outputs the date as 2011/11,14. How do i get it to output it like the following: 14/11/2011??

Upvotes: 0

Views: 764

Answers (2)

malletjo
malletjo

Reputation: 1786

Change this line :

date('Y/m/d');

for

date('d/m/Y');

Upvotes: 0

slugonamission
slugonamission

Reputation: 9642

The issue is with the $date = date... line. I'm not going to give you the direct answer to your question, but have a look at the documentation for date() for starters. Also, you should really be using a DATE database field rather than a string to store that

Upvotes: 1

Related Questions