1.获取上个月第一天及最后一天.
方法1:

  1. echo date('Y-m-01', strtotime('-1 month'));
  2. echo PHP_EOL;
  3. echo date('Y-m-t', strtotime('-1 month'));
  4. echo PHP_EOL;

方法2:

  1. echo date('Y-m-d',mktime(0,0,0,date('m')-1,1,date('Y')));
  2. echo PHP_EOL;
  3. echo date('Y-m-d',mktime(0,0,0,date('m'),0,date('Y')));

2.获取当月第一天及最后一天.

  1. $BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));
  2. echo $BeginDate;
  3. echo PHP_EOL;
  4. echo date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
  5. echo PHP_EOL;

分类: web

标签:   php