douhuang7263 2010-07-14 13:53 采纳率: 100%
浏览 126
已采纳

mysql中的getdate()

I am creating a system which updates the user activity when something is done. I have a variable $userhistory= 'User edited '.$info.' on July 14 2010 or (07-14-2010);

I want to know how can i get the date automatically. for sql query i am using NOW(), but in a variable like $userhistory how do i get the date and it want it only in either of these forms. not along with the time. Also, I am updating the column userhistory in the database, which is a text field. Is this the correct way to do it? How can i save only 5 or 10 of the last few updates?

  • 写回答

2条回答 默认 最新

  • douqiang6036 2010-07-14 14:02
    关注

    If you are using NOW() when you update or write an entry to the database, the column storing the date (userhistory?) should be of DATETIME type.

    Then you'd you'd run your SQL as normal :

    SELECT field1, field2, UNIX_TIMESTAMP(userhistory) FROM table;
    

    Then in PHP, use date() on the database result to format it accordingly:

    // July 14 2010
    date('F j Y', $row['userhistory']);
    // 07-14-2010
    date('m-d-Y', $row['userhistory']); ,
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拓扑学,凸集,紧集。。
  • ¥15 如何扩大AIS数据容量
  • ¥15 单纯型python实现编译报错
  • ¥15 c++2013读写oracle
  • ¥15 c++ gmssl sm2验签demo
  • ¥15 关于模的完全剩余系(关键词-数学方法)
  • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音