【问题标题】:Codeigniter add number to dateCodeigniter 将数字添加到日期
【发布时间】:2016-01-25 17:08:39
【问题描述】:

我有一个数字,我想增加日期的月份,所以如果日期是 2016-01-01 将返回 2016-04-01

$month = 3;
$date = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('date'))));

【问题讨论】:

标签: php codeigniter date


【解决方案1】:

未经测试,但您可以执行以下操作:

$month = 3;
$newdate = date('Y-m-d', strtotime("+".$month." months", str_replace('/', '-', $this->input->post('date'))));

【讨论】:

    【解决方案2】:

    您可以使用以下方法在给定日期添加三个月:

    $Date = date('Y-m-d', strtotime("+3 months", strtotime(str_replace('/','-', $this->input->post('date') ))));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 2011-01-20
      • 2013-01-28
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多