0

How do I do the less than AND greater than $date in wpdb?

$date = ('Y-m-d');

$wpdb->get_results($wpdb->prepare('SELECT * FROM product_history WHERE enddate = "%d";', array($date))); 

I wan't to get history where enddate is today or in present time, BUT also more than 0000-00-00.

Ikke
  • 99,403
  • 23
  • 97
  • 120

1 Answers1

1

Try this one

$wpdb->get_results($wpdb->prepare('SELECT * FROM product_history WHERE enddate >= CURDATE()'));

It will work definitely.

Incase of Date with Time, you have to select field DATETIME in MySQL and in that case you should run query something like

$wpdb->get_results($wpdb->prepare('SELECT * FROM product_history WHERE enddate >= NOW()'));

Using this query, You can filter data from current time.

Mitul Shah
  • 1,556
  • 1
  • 12
  • 34