编辑代码

<?php 
function run_getCurrDifferDayNum()
{
    $result = ["iRet" => 0, "sMsg"=>"ok"];
    // 设置默认天数是 0 
    $differenceInDays = 0;
    // 变量获取
    $startDate = '2024-12-01';
    $currentDate = '2024-12-04 12:00';
    $usedNum = 1;

    // 将过去的日期转换为时间戳
    $pastTimestamp = strtotime($startDate);
    // 获取当前时间的时间戳
    $currentTimestamp = strtotime($currentDate);
    // 计算两个时间戳之间的差值
    $differenceInSeconds = $currentTimestamp - $pastTimestamp;
    // 将秒数差转换为天数
    if ($differenceInSeconds > 0) {
        $differenceInDays = intval($differenceInSeconds / 86400) + 1;
    }
    //如果超出了35天就设置为35天
    if($differenceInDays > 35){
        $differenceInDays = 35;
    }

    $dataNum = intval($differenceInDays - $usedNum);
    //返回结果
    $result['jData'] = [
        'diffNum' => $differenceInDays,
        'dataNum' => $dataNum,
    ];
    return $result;
}
$aa = run_getCurrDifferDayNum();
print_r($aa);