duanji8887 2017-04-09 09:48
浏览 40
已采纳

使用'now()'格式化存储在数据库中的时间

I am storing the time a row was created with now() in my database, type DATETIME.
If i just read out the field where it was stored, it returns 2017-04-09 10:34:31.
I'm trying to format it like this: date('H:i d F Y', $row->created)
("$row->created" is the database field where my time is stored, it is correct.)
This outputs: Notice: A non well formed numeric value encountered in C:\wamp\www\index.php on line 52.
So do i need to format the time differently?
Do i need to store via a different time-outputting function?

  • 写回答

1条回答 默认 最新

  • dongqiao8421 2017-04-09 09:49
    关注

    Instead of this:

    date('H:i d F Y', $row->created)
    

    try this:

    date('H:i d F Y', strtotime( $row->created ));
    

    Explanation: The data returned by mysql query is of string type so you have to change it to suitable type and then convert its format of your choice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况