dongnuochen9449 2013-11-22 20:29
浏览 153
已采纳

如何将MySQL时间戳转换为d-m-yyyy

$newTime = "TIME_FORMAT(date, '%e-%M-Y') AS date";

$result = mysqli_query($connect, "SELECT id, firstname, lastname, email, text, $newTime FROM gastenboek");

This is some information selecten from the database, i want to convert the sql timestamp to php days - months - years (22-11-2013).

The query works fine but date = NULL

it seems that my query is wrong, because when i do SELECT * FROM gastenboek it all works fine.

Error code: Notice: Trying to get property of non-object

I already googled the problem but i can't find the solution.

Sorry for my bad english, and thanks in advanced!

Greetings from Holland

  • 写回答

3条回答 默认 最新

  • drui0508 2013-11-22 20:35
    关注

    You need to use DATE_FORMAT instead of TIME_FORMAT. And I think your format string needs to be tweaked. Try this:

    DATE_FORMAT(date, '%e-%c-%Y') AS date
    

    The docs for TIME_FORMAT say:

    This is used like the DATE_FORMAT() function, but the format string may contain format specifiers only for hours, minutes, seconds, and microseconds. Other specifiers produce a NULL value or 0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀