Php 计算月数并每月生成票据

Php 计算月数并每月生成票据,php,Php,我正在尝试根据用户输入的开始日期和结束日期自动生成支持请求 首先,我将计算两个日期之间的月数,然后我将每月提出支持请求,直到到达结束日期 我正在这样努力 if($frequency=='Monthly') { $ts1 = strtotime($sdate); $ts2 = strtotime($edate); $year1 = date('Y', $ts1); $year2 = date('Y', $ts2); $month1 = date('m', $ts1); $month2

我正在尝试根据用户输入的开始日期和结束日期自动生成支持请求

首先,我将计算两个日期之间的月数,然后我将每月提出支持请求,直到到达结束日期

我正在这样努力

if($frequency=='Monthly') {

 $ts1 = strtotime($sdate);
 $ts2 = strtotime($edate);
 $year1 = date('Y', $ts1);
 $year2 = date('Y', $ts2);
 $month1 = date('m', $ts1);
 $month2 = date('m', $ts2);

 $diff = (($year2 - $year1) * 12) + ($month2 - $month1);

 for($i=1; $i<=$diff; $i++)
 {


    $time = strtotime($sdate);
    $final = date("Y-m-d", strtotime("+1 month", $time));

    $sql = mysqli_query($con, "SUPPORT REQUEST QUERY");
 }
}
if($frequency=='Monthly'){
$ts1=标准时间($sdate);
$ts2=标准时间($edate);
$year1=日期('Y',$ts1);
$year2=日期('Y',$ts2);
$month1=日期('m',$ts1);
$month2=日期('m',$ts2);
$diff=($year2-$year1)*12)+($month2-$month1);

对于($i=1;$i我认为不需要计算月数,除非您想将其存储在数据库中或在某个地方使用它

您只需从用户处获取开始日期和结束日期,并按照您希望的频率按照以下代码提高票证

$startdate = "2017-06-19";//here is start date
$enddate = "2017-08-21";//end date
$tempdate = $startdate;//temporary storing start date
//comparing tempdate is not greater than end date
while(strtotime($tempdate)<=strtotime($enddate))
{
    //this is my sample code. You can replace with yours.
    echo "Raised ticket on ".$tempdate."<br/>";
    $tempdate = date('Y-m-d', strtotime("+1 month", strtotime($tempdate)));
}
试试这个

$sdate = "2017-06-19";
$edate = "2017-08-18";

$d1 = new DateTime($sdate);
$d2 = new DateTime($edate);
$diff = $d1->diff($d2)->m;

$Tickets = array($sdate);
$time = strtotime("+1 month", strtotime($sdate));

for($i=1; $i<=$diff; $i++)
{
    $Tickets[] = date("Y-m-d", $time);
    $time = strtotime("+1 month", $time);
    //$sql = mysqli_query($con, "SUPPORT REQUEST QUERY");
}

var_dump($Tickets);
$sdate=“2017-06-19”;
$edate=“2017-08-18”;
$d1=新日期时间($sdate);
$d2=新日期时间($edate);
$diff=$d1->diff($d2)->m;
$Tickets=数组($sdate);
$time=strottime(“+1个月”,strottime($sdate));
对于($i=1;$i)
$sdate = "2017-06-19";
$edate = "2017-08-18";

$d1 = new DateTime($sdate);
$d2 = new DateTime($edate);
$diff = $d1->diff($d2)->m;

$Tickets = array($sdate);
$time = strtotime("+1 month", strtotime($sdate));

for($i=1; $i<=$diff; $i++)
{
    $Tickets[] = date("Y-m-d", $time);
    $time = strtotime("+1 month", $time);
    //$sql = mysqli_query($con, "SUPPORT REQUEST QUERY");
}

var_dump($Tickets);