自动设置日期输入日期

时间:2021-03-05 14:44:04

标签: php html

所以我有一个日期输入,它会在 8 天后自动设置日期,如下所示:

<input type="date" name="pdate" value="<?php echo date("Y-m-d", time() + 691200); ?>" required>

所以现在这会显示03/13/2021作为日期,但是是否可以跳过星期六和星期日,所以如果8天内的日期是星期六或星期日,它会在插入后自动设置日期为Money?

2 个答案:

答案 0 :(得分:0)

是的,你可以在 PHP 中使用 DateTime

如下图

new \DateTime('+8 weekdays');

答案 1 :(得分:0)

<?php

$date = new \DateTime('+8 days');
$date = shiftDate($date);
function shiftDate($date){
    if (in_array((int)$date->format('N'), [6,7])){
        $date->add(new \DateInterval('P1D'));
        $date = shiftDate($date);
    }
    return $date;
}
var_dump($date);

此处的工作代码https://3v4l.org/vmomV