如何从php中的phpmyadmin获取日期(d,m,y)? [重复]

This question already has an answer here:

I want to fetch date format from (y,m,d) to (d,m,y).In my database I already insert data like date and images so many around 400 images.I dun want to insert again.phpmyadmin

The following is to fetch from database.

<?              
                            $sql = "SELECT * FROM  ShowFillter GROUP BY Image_Date order by Image_Date desc";
                            $objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");
                            while($objResult1 = mysql_fetch_array($objQuery))
                            {
                        ?>
                        <li class="filter" data-filter="<?=$objResult1['Image_Date'];?>">
                            <a href="#">
                                <?=$objResult1['Image_Date'];?></a>
                        </li>

                        <? 
                            }    
                        ?>

The following is i tried it out to fetch from database.But It only show (Year ,Month,day) format.

<?              
                            $sql = "SELECT * FROM  ShowFillter GROUP BY DATE_FORMAT(Image_Date, '%d/%m/%Y') order by DATE_FORMAT(Image_Date, '%d/%m/%Y') desc";
                            $objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");
                            while($objResult1 = mysql_fetch_array($objQuery))
                            {
                        ?>
                        <li class="filter" data-filter="<?=$objResult1['Image_Date'];?>">
                            <a href="#">
                                <?=$objResult1['Image_Date'];?></a>
                        </li>

                        <? 
                            }    
                        ?>

Here is the result resultIs it possible to fetch (day,month,year) format? If its possible ,guide me please.

Thanks :)

</div>

When you print your image date do:

<?=date('d-m-Y', strtotime($objResult1['Image_Date])); ?>

This will echo 27-12-2013

More here http://php.net/manual/en/function.date.php

You can correct the output in php using strtotime and date:

$new_Image_Date = date("d,m,Y", strtotime($objRsult1['Image_Date']));

strtotime takes the string that's returned from your query and parses it into a timestamp. You can then convert it to the correct format using date.

So your snippet would ultimately be something like:

<?              
  $sql = "SELECT * FROM  ShowFillter GROUP BY DATE_FORMAT(Image_Date, '%d/%m/%Y') order by DATE_FORMAT(Image_Date, '%d/%m/%Y') desc";
  $objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");
  while($objResult1 = mysql_fetch_array($objQuery))
  {
?>
<li class="filter" data-filter="<?=date("d,m,Y", strtotime($objResult1['Image_Date']));?>">
   <a href="#">
     <?=date("d,m,Y", strtotime($objResult1['Image_Date']));?>
   </a>
</li>
<? 
  }    
?>

Check the references below if you need more info:

strtotime() doc page

date() doc page

You can also try this in your query, so the date is already formatted.

SELECT id, Image_Id, Image_Name, Image_Type, DATE_FORMAT(Image_Date, '%d,%m,%y') AS Image_Date, `status` 
FROM ShowFilter 
GROUP BY Image_Date 
ORDER BY Image_Date DESC

Read date_format