就像標題所說,我怎樣才能使用這個日期函數來將它保存爲一個字符串,或者我可以稍後從數據庫中獲取它?將數據保存到數據庫並使用PHP獲取
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$newsTitel = $_POST['title'];
$submitDate = date('Y-m-d g:i:s A');
$newsContent = $_POST['newstext'];
mysql_query("INSERT INTO $tbl_name (Nieuwstitel, Nieuwsbericht, Postdatum)
VALUES('$newsTitel', '$newsContent', '$submitDate') ");
echo "Het bericht is successvol geplaatst!";
echo date('Y-m-d g:i:s A');
這顯示例如日期的消息:2012年,只有當它是個全長:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM $tbl_name ORDER BY newsid DESC");
$count = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
$count = mysql_num_rows($result);
echo "<table class='newsList'>";
echo "<tr><div id='nav'><th align='left'>".$row['Nieuwstitel']."</th>
<th class='right'>".$row['Postdatum']."</div></tr>";
echo "<tr><td colspan='2'>".$row['Nieuwsbericht']."<br/></td></tr>";
echo "</table>";
if ($count == 0){
echo "<center><p>No news at the moment!</p><p> </p></center>";
}
}
}
將日期保存爲datetime或timestamp(例如在MySQL中),然後在使用/顯示它們時將其格式化。 http://dev.mysql.com/doc/refman/5.0/en/datetime.html – 2012-08-01 17:48:17
這對谷歌先生很容易。 – fdomig 2012-08-01 17:48:56