dongtiaozhou4914 2015-08-25 08:55
浏览 43
已采纳

在我的自定义表格中,我希望从表格中获取用户的差异为15天。 Date_diff函数不能正常工作?

 <?php
    global $wpdb;

    $today =date("Y-m-d H:i:s");

    foreach( $wpdb->get_results("SELECT * FROM tablename WHERE DATEDIFF($today,end_date)<=15 ") as $key => $row){
     // each column in your row will be accessible like this
        echo $my_column = $row->user_id;
        echo"<br/><br/>";
    }

?>

I have create a function in which i want the where the user registration ending date is coming to close to 15 days so i want the value in foreach loop. I have got some success. In my custom table i am getting value as the date in this format -> 2016-06-07 12:53:55 So i am printing the value $today variable in same format like to get the difference but it is printing nothing but if i remove where clause, I am able to get the values then. I dont know what i am doing wrong here. All i want is when it comes close to the 15 days before this date like 07 june 2016 so i will get those user ids which are going to expire. Please Can you help me I will definitely appreciate it.

  • 写回答

2条回答 默认 最新

  • doucheng3811 2015-08-25 09:25
    关注
    1. Use curdate() as a built in function of mysql, so you dont need to worry about passing a string into the query.
    2. switch datediff order to get the expected result.
    3. Add a filter to remove the ones that already expired.
    SELECT * FROM tablename 
    WHERE DATEDIFF(end_date,curdate())<=15 
    and end_date>=curdate()
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作