dongyue8640 2011-07-30 13:20
浏览 36

如何模拟MySQL表中的2个时间戳字段?

I know you can only have 1 timestamp per table in mysql. But I need 2. One for when an article was created and one for everytime it's updated. The latter is the one that will be changing most of the time so I decided to make that the timestamp field. For the other one, how can I prepare the time in PHP so that it looks just like a timestamp when inserted into the database:

2011-07-29 03:28:20

And if this string is prepared in PHP, will the usual ways of formatting it work, e.g.:

    $time = strtotime($timestamp);
    $date = date('n/d/Y @ g:i a', $time);
  • 写回答

4条回答 默认 最新

  • dssjxvbv918586 2011-07-30 13:23
    关注

    You can use a datetime field in order to store insert time (use now() function of mysql). Use instead a timestamp field to store update time.

    create table mytb (
    id int not null auto_increment primary key,
    article varchar(50),
    ins_time datetime,
    upd_time timestamp not null default current_timestamp on update current_timestamp
    ) engine = myisam;
    
    insert into mytb (
    article,ins_time) values ('bla bla bla', now());
    
    update mytb set article = 'bla bla' where id = 1
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度