<?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.