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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置