Coo*_*uke 3 php mysql date-format
这对许多人来说听起来像是一个非常简单的问题,但我似乎无法获得基本的date_format来处理我的mySQL语句然后使用php显示.这是我目前的代码:
$result = mysql_query("SELECT *, DATE_FORMAT('timestamp', '%W %D %M %Y') as date FROM articleDB WHERE userID='".$_SESSION["**"]."' ORDER BY timestamp DESC LIMIT 8");
Run Code Online (Sandbox Code Playgroud)
然后尝试使用以下方式显示它:
echo ' Posted: '.$row['timestamp'].'';
Run Code Online (Sandbox Code Playgroud)
我想要的是将日期从PHP myAdmin时间戳格式化为我想要的格式.
干杯
) or nothing at all instead of single-quotes (在查询中的字段周围使用反引号(`` '`):
$result = mysql_query("SELECT *, DATE_FORMAT(`timestamp`, '%W %D %M %Y') as date FROM articleDB WHERE userID='".$_SESSION["**"]."' ORDER BY timestamp DESC LIMIT 8");
Run Code Online (Sandbox Code Playgroud)
反引号('' ) creates a reference to a table member, single-quotes creates a string (' ). You were basically trying toDATE_FORMAT the string'时间戳'` 而不是字段.
此外,由于您as用于创建字段别名,因此您希望在输出时使用别名引用该字段:
echo ' Posted: '.$row['date'];
Run Code Online (Sandbox Code Playgroud)