Hello,

I'm developing a custom plugin for wordpress and I've got to retrieve some numbers from a table where the value in the expiry_date column is greater than value that I've stored in a variable called $scheduleddate (That is, I need to retrieve numbers that haven't expired as at the $scheduleddate). Here is what I've tried:

$scheduled_date = strtotime($year."-".$month."-".$day);
$scheduleddate = date('Y-m-d',$scheduled_date);

  global $wpdb;
  $table_name = $wpdb->prefix . "subscribers";
  $result = $wpdb->get_results("SELECT number FROM " . $table_name .
            " WHERE list_id=" . $list . " AND expiry_date > " .  $scheduleddate);

When I tested it, I still ended up with the numbers that had already expired (I echoed the numbers so that I could see whether they were the ones I needed). I need to retrieve the numbers that are NOT expired as at the time in the $scheduleddate. What's the correct way to write the query? The expiry_date column is in the date format in the database table. (And if it's important, the $year, $month, and $day variables are gotten from $_POST and I need them that way.)

Am I meant to use $wpdb->prepare as well?

Thanks in advance!

Hello admiralchip,

Please try this
$result = $wpdb->get_results("SELECT number FROM " . $table_name . " WHERE list_id=" . $list . " AND expiry_date > '".$scheduleddate."'");

The above query puts your date as string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.