如何转换以下日期:2016-11-4 18:31:27到NOV 04在php和mysql中?

时间:2016-11-05 11:00:44

标签: mysql date

我有以下日期: 2016-11-4 18:31:27,2016-11-1 18:31:27,2016-11-6 18:31:27,2016-11-7 18 :31:27 我希望将它转换为 NOV 04,NOV 01,NOV 06 当我执行以下代码时我得到 jan 01,jan 01,jan 01,jan 01

<?php
        $sqluseractivity = "SELECT user_register_date FROM `mlm_users` WHERE (`user_register_date` > DATE_SUB(now(), INTERVAL 10 DAY))";
        $resultuser = $con->query($sqluseractivity);

        while($rowusers = $resultuser->fetch_assoc())
{

        $datetimeFromMysql = $rowusers['user_register_date'].'</br>';

        $dbtime = $datetimeFromMysql;

        $time = strtotime($dbtime);

        $myFormatForView = date("M d", $time);   

        echo $myFormatForView.'</br>' ;


}
?>

1 个答案:

答案 0 :(得分:1)

一种选择是使用DATE_FORMAT在MySQL端处理此问题:

SELECT DATE_FORMAT(user_register_date, '%b %d')
FROM mlm_users
WHERE user_register_date > DATE_SUB(now(), INTERVAL 10 DAY)