[英]How to set custom month start date and end date in php
我的薪水月从上个月的26号开始,到本月的25号结束,即2月是2016-01-26至2016-02-25。
我需要如下的输出
$date = '2014-02-27';
echo date('F', strtotime($date)); = "March" //if date > 25 print next month
我相信您要做的就是一天:
$date = '2014-02-27';
$day = date('d', strtotime($date));
然后看看是否大于26,增加一个月
$month = date('F', strtotime($date));
if($day > 26)
{
$ts = mktime(0, 0, 0, date("n", strtotime($date)) + 1, 1);
$tmpNewDate = date("Y-m-d H:i:s", $ts);
$month = date('F', strtotime($date));
}
echo $month;
试试这个,我准备了几个日期输入:
<?php
$input_date = '2014-2-2';
// $input_date = '2014-2-27';
// $input_date = '2014-12-27';
$date = DateTime::createFromFormat('Y-m-d', $input_date);
$next_month = null;
$year = $date->format('Y');
$next_month = $date->format('m');
if ($date->format('d') >= 26)
$next_month = intval($date->format('m')) + 1;
if ($next_month == 13){
$next_month = 1;
$year = intval($year) + 1;
}
echo "next month = " . $next_month . ", year = " . $year;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.