如何在链接php中传递当前日期

时间:2019-01-20 06:34:08

标签: php date datepicker

我想在菜单链接URL中传递当前日期。我在传递from: method="get"之类的url中的一些index.php?hotel_id=1&adult=1数据时必须面对一个错误,但是在我的页面中,如果我没有通过任何检查,则需要在签入,签出输入框中显示日期-在结帐数据输入字段中,它将在明天和后天的输入框中显示。

这是我的代码:

<form action="index.php" method="GET">
        <div class="hotel-level">
            <label class="radio-inline">
                <input type="radio" name="hotel_id" value="1" <?php if (isset($_GET['hotel_id']) && $_GET['hotel_id'] == '1')  echo 'checked'; else echo 'checked';?> > Ascott The Residence
            </label>
            <label class="radio-inline">
                <input type="radio" name="hotel_id" value="2" <?php if (isset($_GET['hotel_id']) && $_GET['hotel_id'] == '2')  echo 'checked';?>> Ascott Palace
            </label> 
        </div>
        <ul>
            <li>  
                <div class="input-group date" data-date-format="dd.mm.yyyy">
                <input type="text" id="checkin" class="form-control datepicker" name="checkin" placeholder="Check-in" value="<?php echo $arrival_date; ?>" autocomplete="off" required/>
                <div class="input-group-addon" >
                    <span class="fa fa-calendar checkin-cal"></span>
                </div>
                </div>
            </li>
            <li>
                <div class="input-group date" data-date-format="dd.mm.yyyy">
                <input type="text" id="checkout" class="form-control datepicker" name="checkout" placeholder="Check-out" value="<?php echo $departure_date; ?>" autocomplete="off" required/>
                <div class="input-group-addon" >
                    <span class="fa fa-calendar checkout-cal"></span>
                </div>
                </div>
            </li>
            <li>
                <select name="adult" class="form-control">
                    <option value>Select Person</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                </select>
            </li>
        </ul>
        <div class="hotel-submit">
            <input type="submit" class="medium brown button"  name="submit" value="Submit"/>
    </form>

问题图片:

1 个答案:

答案 0 :(得分:0)

我得到了我的回答,谢谢大家。

仅使用if else语句:

$d=strtotime("+1 day");
$d1=strtotime("+2 day");
if($chkindate == ''){
    $chkindate = date('Y-m-d',$d);
}
if($checkout == ''){
    $checkout = date('Y-m-d',$d1);
}