dua27031 2014-06-30 06:56
浏览 62
已采纳

如何从存储在变量中的日期中减去月份?

If I use this way I can get what I want :

echo Date("m/Y", strtotime("04/2014 -1 Month"));
// 03/2014

but I need to generalize this to subtract from unknown date like this :

$date1 = date("m/Y", strtotime("+1 month"));
$date = date("m/Y", strtotime("".$date1." -$f month"));

I get wrong answers for date it show 01/1970 I want to know is it possible to use the date variable inside strtotime ? and is my way to use it right or wrong?

  • 写回答

2条回答 默认 最新

  • dtnwm4807 2014-06-30 07:08
    关注

    You can also use modify function.

    $date = new DateTime('2014-04-01');
    $date->modify('-1 month');
    echo $date->format('m-Y');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗