2013-06-08 20:25
浏览 1.2k


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.

图片转代码服务由CSDN问答提供 功能建议


我的目标是对结果执行某些操作( 喜欢减去1天)。 我在网上找到了 date_sub ,但要求是它的参数应该是 DateTime 类型。

警告 :date_sub()要求参数1为DateTime,字符串在第107行的C:\ xampp \ htdocs \ blog \ wp-content \ themes \ twentyten \ header.php中给出 \ n

如何对MySQL时间戳数据类型格式执行减法,或者是否存在以 DataTime 格式返回当前日期的Worpdress函数?

您 总是感谢帮助。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题