I am trying to call the date column from the MySQL database. However I dont know that how could i change the format to (mm/dd/yy). My codes are as follows:
<?php
$id=$_GET['ref'];
$sql=mysql_query("select * from politics where id='$id'");
while($row=mysql_fetch_array($sql))
{
?>
<div class="textleft">
<?php echo $row['date'] ?><br />
<?php echo $row['matter'] ?>
</div>
<?php
}
?>
<!--matter ends-->
</div>
<!--topic ends-->
<?php
}
?>
Use DATE_FORMAT of MYSQL to improve performances:
select *, DATE_FORMAT(date,'%m/%d/%Y') AS niceDate
from politics
where id='$id'
you could change
<?php echo $row['date'] ?><br />
to
<?php echo date("m/d/y",strtotime($row['date'])); ?><br />
输出$row['date']
时更改日期格式:
<?php echo date("m/d/y", strtotime($row['date'])); ?><br />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.