我在mysql数据库中有一个列类型DATE
,并希望以这样的格式获取日期 - 21-jan
。
$stmt = $db->query('SELECT id, date, title, category FROM posts ORDER BY date DESC');
while($row = $stmt->fetch()){
$date = strtotime($row['date']);
$date = date_format($date, "d-M"); // line 49
警告:
date_format() expects parameter 1 to be DateTimeInterface, integer given... on line 49
任何帮助?
答案 0 :(得分:1)
尝试这样做:
$date = strtolower(date("d-M", $date));
答案 1 :(得分:1)
使用date函数代替date_format:
$stmt = $db->query('SELECT id, date, title, category FROM posts ORDER BY date DESC');
while($row = $stmt->fetch()){
$date = date("d-M", strtotime($row['date']));
$formatedDate = strtolower($date);