How to subtract 4 months from today's date?

后端 未结 2 1046
北恋
北恋 2021-01-01 13:34

I need to declare two dates in \"Ymd\" format: $toDate and $fromDate.

$toDate represents today\'s date and

相关标签:
2条回答
  • 2021-01-01 13:55

    Use the magic of strtotime:

    $fromDate = date("Ymd", strtotime("-4 months"));
    
    0 讨论(0)
  • 2021-01-01 14:03

    see the code below...

    $fourmonthsback = date("Ymd", mktime(0, 0, 0, date("m")-4, date("d"),   date("Y")));
    

    OR

    $fourmonthsback = mktime(0, 0, 0, date("m")-4, date("d"),   date("Y"));
    
    0 讨论(0)
提交回复
热议问题