0

I need select active posts of wordpress with a PHP script that answer date roles.

This is the select that I tried, but it didn't work:

select post_title, post_date from wp_posts 
where post_date between 2016-01-25 and 2016-01-01

Before, I tried this:

select post_title, post_date from wp_unp_posts where

Date_sub(curdate(), interval '25' day)

or:

select post_title, post_date from wp_unp_posts where

post_date => curdate() - 25

Nothing return results.

What is the correct construction of this query?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • 1
    Possible duplicate of [How to calculate the difference between two dates using PHP?](http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – Andy Hoffner Jan 25 '16 at 16:33

1 Answers1

0

First of all enclose the dates in single quotes since it is of string type. And also exchange the order of dates such that first date should be less than the second date. Try this:

select post_title, post_date from wp_posts where post_date between '2016-01-01' and '2016-01-25';
Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38