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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题