Than Htut Oo Than Htut Oo - 2 months ago 7
MySQL Question

How to fetch date(d,m,y) from phpmyadmin in php?

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
result
Is it possible to fetch (day,month,year) format?
If its possible ,guide me please.

Thanks :)

Answer

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