dongzaotiao2863 2013-02-12 22:17
浏览 107
已采纳

使用PHP存储时间戳:date()或MySQL:FROM_UNIXTIME()?

This may be trivial, but when I want to store a timestamp value (returned by, say, time()) into a TIMESTAMP column in my MySQL table, which of these two are preferable:

function storeTime($timestamp) {
   // Option one:
   $query = "INSERT INTO faketable (datecol) VALUES (FROM_UNIXTIME(".$timestamp."))";
   // Option two:
   $query = "INSERT INTO faketable (datecol) VALUES (".date("YY-MM-DD HH:MM:II", $timestamp).")";
}

Is there even a difference?

EDIT: Sorry, meant date(), not strtotime()...

EDIT 2: NOW() doesn't cut the mustard, the actual timestamp is a paramater sent to my method. I don't know what it is in advance.

EDIT 3: I really shouldn't be asking questions at this time of night. The column in question is, in fact, a TIMESTAMP column, not a DATETIME column.

  • 写回答

3条回答 默认 最新

查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳
  • ¥15 wpf dategrid表头排序图标自定义
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 写一个利用ESP32自带按键和LED控制的录像代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。