duannue2455 2009-01-31 15:35
浏览 49

我需要使用php更改日期格式

Hi I have looked at a question already posted about this and tried to adapt my code to do a simlar thing. Basicly I have a field in my mysql database that has the date in this format yyyy-dd-mm i need to the format to be dd-mm-yyyy. Currently my code is getting stuck on the line echo "<td><strong> ("d/m/y",". $row['date'] .")</strong></td>"; and reads this Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'. Not sure how to fix this any ideas I would be greatful.

$result = mysql_query("SELECT * FROM dbGigs WHERE CURDATE() < date ORDER BY date");

echo "<table class=\"gigs\">
<tr>
<th>Venue</th>
<th>Town</th>
<th>Date</th>
<th>Time</th>
<th>Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><strong>" . $row['venue'] . "</strong></td>";
  echo "<td><strong>" . $row['town'] . "</strong></td>";
  echo "<td><strong> ("d/m/y",". $row['date'] .")</strong></td>";
  echo "<td><strong>" . $row['time'] . "</strong></td>";
  echo "<td><strong>" . $row['status'] . "</strong></td>";
  echo "</tr>";
  • 写回答

4条回答 默认 最新

  • doushan1850 2009-01-31 15:39
    关注

    First things first

      echo "<td><strong> ("d/m/y",". $row['date'] .")</strong></td>";
    

    This line looks wrong; I suspect it ought to read something like

      echo "<td><strong>" . date( "d/m/y", $row['date'] ) . "</strong></td>";
    

    Note the missing function call and concatenation operators. Incidentally, while this is syntactically correct (so far as I can see), it may not do what you're looking for, depending upon what $row['date'] actually contains - it needs to be a Unix timestamp for date() to grok it properly.

    To obtain the date as a Unix timestamp, you can use the MySQL function UNIX_TIMESTAMP() when selecting the date, e.g.

    SELECT *, UNIX_TIMESTAMP(date) AS date_ts FROM ...
    

    You can then access $row['date_ts'] as normal, and pass it into the date() function for formatting. Alternatively, you can use something like strtotime() to parse the current value being returned in order to get a timestamp from that.

    A further alternative is to have MySQL format the date on your behalf, using its DATE_FORMAT() function; again, you can access this value returned from the query and print it out.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器