dsxay48646 2019-07-13 08:47
浏览 307
已采纳

如何使用CURRENT_TIMESTAMP添加截止日期?

I'm trying to make a library booking system so when user borrows a book, they will have a due date set 7 days after the issue date (set as CURRENT_TIMESTAMP). However, is there a way for me to just use the CURRENT_TIMESTAMP + 7 days in the php/html code? or do I need to add another table column to set the due date variable in the database?

I have tried to change a variable (fine) in the database which is not needed in my database with the due date. However, this messes up the whole thing which the data wont show.

So currently, I'm trying to add 7 days to the IssueDate variable via DATE_ADD function. However, this won't allow the code to show.

                                        <tr>
                                            <th>#</th>
                                            <th>Book Name</th>
                                            <th>ISBN </th>
                                            <th>Issued Date</th>
                                            <th>Due Date</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
<?php 
$sid=$_SESSION['stdid'];
$sql="SELECT tblbooks.BookName,tblbooks.ISBNNumber,tblissuedbookdetails.IssuesDate,tblissuedbookdetails.ReturnDate,tblissuedbookdetails.id as rid,tblissuedbookdetails.fine from  tblissuedbookdetails join tblstudents on tblstudents.StudentId=tblissuedbookdetails.StudentId join tblbooks on tblbooks.id=tblissuedbookdetails.BookId where tblstudents.StudentId=:sid order by tblissuedbookdetails.id desc";
$query = $dbh -> prepare($sql);
$query-> bindParam(':sid', $sid, PDO::PARAM_STR);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{               ?>                                      
                                        <tr class="odd gradeX">
                                            <td class="center"><?php echo htmlentities($cnt);?></td>
                                            <td class="center"><?php echo htmlentities($result->BookName);?></td>
                                            <td class="center"><?php echo htmlentities($result->ISBNNumber);?></td>
                                            <td class="center"><?php echo htmlentities($result->IssuesDate);?></td>
                                            <td class="center"><?php if($result->ReturnDate=="")
                                            {?>
                                            <span style="color:red">
                                             <?php   echo htmlentities("Not Return Yet"); ?>
                                                </span>
                                            <?php } else {

                                            echo htmlentities($result->SELECT DATE_ADD(d,7,IssuesDate));
                                        }
                                            ?></td>
                                              <td class="center">

                                            <a href="test-return.php?rid=<?php echo htmlentities($result->rid);?>">
                                            <button class="btn btn-primary"><i class="fa fa-edit "></i>Extend</button> 

                                            </td>

                                        </tr>
 <?php $cnt=$cnt+1;}} ?>                                      
                                    </tbody>

Any "working codes" will not show the results in the "due date" table column and those that are not will just said there's unexpected variable, symbols, etc.

  • 写回答

2条回答 默认 最新

  • douxie1894 2019-07-13 08:56
    关注

    You need to caclculate 7 days in PHP rather than SQL. Use following code in your else block to calculate and display the Due Date.

    $datetime = new DateTime( $result->IssuesDate );
    $datetime->modify('+7 days');
    echo $datetime->format('Y-m-d');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记