doudan4834 2014-09-17 07:54
浏览 78
已采纳

如何使用php比较mysql查询中的两个日期时间

I want to compare two datetime variable witch one of them is current server time and one of them is stored in mysql database i am running this simple piece of code and it wont work and says it is a syntax error i am wondering what can i do

    <?php include("includes/student_session.php");?>
<?php confirm_logged_in();?>
<?php include("includes/connection.php");?>
<?php 
        date_default_timezone_set("");
        $now_date=date("Y-m-d H:i:s");

    $query1="select exam_id from exam where {$now_date} > start_date";
    $result=mysqli_query($cnn,$query1);
    if($result){

    $row=mysqli_fetch_array($result);
    echo $exam_id. "exists";

    }else
    {echo mysqli_error($cnn);}

?>
  • 写回答

3条回答 默认 最新

  • dousha7645 2014-09-17 08:00
    关注
    $query1="select exam_id from exam where {$now_date} > start_date";
    $result=mysqli_query($cnn,@query1);
    

    I think the error is because you are using @ insteal of $. Also your query seems to be wrong. You should compare values with fields change it to

       $query1="select exam_id from exam where start_date > '{$now_date}'";
       $result=mysqli_query($cnn,$query1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?