gpt4 book ai didi

php - 计算月数并生成每个月的票证

转载 作者:行者123 更新时间:2023-12-03 23:05:48 25 4
gpt4 key购买 nike

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

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

我正在尝试这样

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");
}
}

例如:开始日期是2017-06-19,结束日期是2017-08-21,那么支持请求应该生成3次,分别是2017-06-19、2017-07-19和2017- 08-19

请建议如何继续

最佳答案

我认为没有必要计算月数,除非你想将其存储在数据库中或在某个地方使用它。

您可以仅从用户处获取开始日期和结束日期,并按照此代码按照您想要的频率提出票证。

$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)));
}

输出

Raised ticket on 2017-06-19
Raised ticket on 2017-07-19
Raised ticket on 2017-08-19

关于php - 计算月数并生成每个月的票证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44537862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com