我用这段代码得到了日期:
<?php $query = "SELECT `news_id`, `headline`, `category`, `body`, `date` FROM `news` ORDER BY `news_id` DESC"; $news_resource = mysql_query($query) or die(mysql_error()); ?>
日期现在看起来像这样(2012-07-24),但我需要它作为24.07.2012
我已经搜索了一个解决方案并尝试过这样的事情:
$mysql = "SELECT DATE_FORMAT(date, „%d.%m.%Y”) AS date FROM news;";
我不知道在旧代码中添加此内容以及必须更改的内容。希望你能帮忙。
编辑#1:在phpMyAdmin中,该行称为“日期”,而类型我使用“日期”......
编辑#2:我试过这个
<?php $query = "SELECT `news_id`, `headline`, `category`, `body` FROM `news` ORDER BY `news_id` DESC"; $query = "SELECT DATE_FORMAT(date,\"%d.%M.%Y\") AS `date` FROM `news`"; $news_resource = mysql_query($query) or die(mysql_error()); ?>
并且日期正确,但现在我收到了错误:
编辑#3:是的,我自己搞定了!
<?php $query = "SELECT `news_id`, `headline`, `category`, `body`, DATE_FORMAT(date,\"%d.%m.%Y\") AS `date` FROM `news` ORDER BY `news_id` DESC"; $news_resource = mysql_query($query) or die(mysql_error()); ?>
再见!
答案 0 :(得分:2)
这是我自己解决的问题。
我之前获得的代码(国际日期):
<?php $query = "SELECT `news_id`, `headline`, `category`, `body`, `date` FROM `news` ORDER BY `news_id` DESC"; $news_resource = mysql_query($query) or die(mysql_error()); ?>
更改了代码(德国日期):
<?php $query = "SELECT `news_id`, `headline`, `category`, `body`, DATE_FORMAT(date,\"%d.%m.%Y\") AS `date` FROM `news` ORDER BY `news_id` DESC"; $news_resource = mysql_query($query) or die(mysql_error()); ?>