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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改