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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度