来自mysql数据库的日期格式

时间:2017-01-21 22:10:08

标签: php date

我在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

任何帮助?

2 个答案:

答案 0 :(得分:1)

尝试这样做:

$date = strtolower(date("d-M", $date));

看看日期功能: http://php.net/manual/pt_BR/function.date.php

答案 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);