dorpbn1027 2013-06-08 20:25
浏览 1434
已采纳

如何从MySQL时间戳数据类型的日期中减去一天?

In my Worpdress site I am using the function current time to return the current date in MySQL timestamp data type format.

My goal is to perfom some operations on the result (like substracting 1 day). I found on the web date_sub but the requirement is that its parameter should be a DateTime type.

Warning: date_sub() expects parameter 1 to be DateTime, string given in C:\xampp\htdocs\blog\wp-content\themes\twentyten\header.php on line 107

How can I perform substraction on the MySQL timestamp data type format, or is there a Worpdress function that returns current date in DataTime format?

You help is always appreciated.

  • 写回答

3条回答 默认 最新

  • dounabi6295 2013-06-08 20:56
    关注

    Something like this should work:

    $date = new DateTime();
    $date->sub(new DateInterval("P1D"));
    echo $date->format("Y-m-d H:i:s");
    

    If you aren't familiar with it, you should look at PHP SPL Date/Time classes. They are immensely useful and make this type of thing very easy.

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

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题