【问题标题】:Calculate days stay based on checkin to checkout when check out time is at 12.00 noon退房时间为中午 12:00 时,根据入住到退房计算住宿天数
【发布时间】:2017-09-30 19:43:03
【问题描述】:
<?php
    $today = date('Y-m-d');
    $sql = "SELECT * FROM roombooking where enddate>='$today'" ;

    $result1 = $db->query($sql);
    if ($result1->num_rows > 0){
    echo"
    <div class=table-responsive border >
      <table class=table>
        <tr>

        <th>Room Type</th>
        <th>Room Number</th>
        <th> Status </th>
        <th> Check-in date </th>
        <th> Check-Out date  </th>
        <th>Stay Time</th>
        <th colspan='2'>Action </th>
        </tr>";
        // output data of each row

        // output data of each row
        while ($row = $result1->fetch_assoc()) 
        { echo "<tr>
               <td>".$row["roomtype"]."</td>
               <td>".$row["roomnumber"]."</td>
               <td>".$row["bkg_status"]."</td>
               <td>".$d1=$row["bkg_clientintime"]."</td>
               <td>".$d2=$row["bkg_clientouttime"]."</td>


               </tr>";
            }
     echo "</table></div>";
    }else { echo "<br>"."<div class='alert alert-info col col-md-6 col-md-offset-2'> SORRY NO CHEK OUT FOUND FOR TODAY 

    </div> ";}
?>
//here from $d1 which is booking check-in-date and $d2 which is check-out-date 
HELP REQUIRED // important checkout date time is 12.00 noon 
HELP REQUIRED 2// FINDING TOTAL Number of days stay 

any suggestion are greatly appreciated 
tried here date_diff / it again gives hours or days but have to find based on
12.00 noon important checkout otherwise new day will be added  how to achieve this part  kindly guide

【问题讨论】:

  • $d2 后我想回显客人的总停留天数如何计算?如果退房时间是中午十二点重要

标签: php datetime datediff


【解决方案1】:

这里最简单的方法是在 mysql 上计算不同的日期

SELECT *,
  DATE_DIFF(DATE(bkg_clientintime), DATE(bkg_clientouttime)) AS no_days
FROM roombooking

【讨论】:

  • 感谢 Dilipen D 先生 .. 但是如何根据退房时间检查日期差异是在中午 12 点而不是日期更改 .. 客户可能会在退房时间前 5 小时登记入住中午 12 点,因此他将在这里支付完整的天数.. 然后我们需要根据不同的剩余日期计算剩余时间
  • 我想首先你想找到不同的总小时数并将其转换为天数````SELECT CEIL(TIMESTAMPDIFF(HOUR,'2009-05-18 11:45:42','2009- 05-20 15:16:39')/24) AS no_days;```
  • 嗨,datediff 帮助获取了数据以及进出天数的差异,但是如果客人早上 5 点进来,他的退房时间是中午 12 点,所以当客人在凌晨 1 点离开时晚上它只会显示 1 天,因为它应该显示 2 天,例如从凌晨 5 点到中午 12 点 = 1 天,从中午 12 点到凌晨 1 点 1 天,因此 2 天停留如何实现这一点,谢谢你的帮助很有价值而且非常有帮助//对不起,我错误地投了两次票,但是当我理解只选择正确答案的勾号时,我做到了,为了控制伤害,我加了两次
  • 使用 CEIL 的 ROUND 方法。它会返回你期望的答案
  • 嗨 Dilipen D 感谢您提出宝贵意见','2009-05-18 15:16:39')/24) AS no_days '' & '' SELECT ROUND(TIMESTAMPDIFF(HOUR,'2009-05-18 1:30:00','2009-05- 18 15:16:39')/24) AS no_days'' 结果是 01 天,但这是错误的,因为退房时间是中午 12 点而不是中午
猜你喜欢
  • 2016-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 1970-01-01
相关资源
最近更新 更多