您好我试图将sql的日期输出从yyyy / mm / dd更改为dd / mm / yyyy
当我通过表单上的日期选择器输入日期时,日期不会保存在mySQL中。 (wil输入only 0000-00-00)
如果我手动将日期输入MySQL,那么它只会显示今天的日期。
我正在使用以下代码:
$result = mysql_query("SELECT * FROM overboekingen")
while($row = mysql_fetch_array( $result )) {
echo '<td>' . $row['datum_overboeking'] = date('d-m-Y') . '</td>';
答案 0 :(得分:0)
试试这种类型的解决方案
$TodayDate = "2014-03-07"; //OR the date from database. It means the date you will get from database
$FormatedDate = date("d-m-Y", strtotime($TodayDate));
答案 1 :(得分:0)
这样你可以把条件
$result = mysql_query("SELECT * FROM overboekingen")
while($row = mysql_fetch_array( $result ))
{
$databaseDate = $row['YOUR DATABASE DATE FIELD NAME'];
$FormatedDate = date("d-m-Y", strtotime($databaseDate));
echo '<td>' . $row['datum_overboeking'] = $FormatedDate . '</td>';
}
答案 2 :(得分:0)
我更进了一步,我现在可以在数据库中正确地插入数据了,只有当我在我的web应用程序中回显它再次将它拉出SQL时,它才能正确显示mySQL的日期。
这段代码似乎不正确:
echo '<td>' . $row['datum_overboeking'] = strtotime($row), date('m-d-Y') . '</td>'
答案 3 :(得分:0)
尝试使用此过程以数据库显示具有所需日期格式的日期
$result = mysql_query("SELECT * FROM overboekingen")
while($row = mysql_fetch_array( $result ))
{
$databaseDate = $row['YOUR DATABASE DATE FIELD NAME'];
$FormatedDate = date("d-m-Y", strtotime($databaseDate));
echo '<td>' . $row['datum_overboeking'] = $FormatedDate . '</td>';
}
答案 4 :(得分:-2)
愿这会帮到你
$TodayDate = "2014-03-07"; //OR the date from database. It means the date you will get from database
$FormatedDate = date("d-m-Y", strtotime($TodayDate));