2016-01-25 65 views
0

我需要选择wordpress的活动文章和PHP脚本来回答日期角色。mysql与php的时间间隔选择日期

这是选择,我试过,但没有奏效:

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

之前,我尝试这样做:

select post_title, post_date from wp_unp_posts where 

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

或:

select post_title, post_date from wp_unp_posts where 

post_date => curdate() - 25 

没有回报结果。

此查询的正确结构是什么?

+1

的可能的复制(http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-两个日期使用PHP) – ahoffner

回答

0

首先用单引号括住日期,因为它是字符串类型。并且交换日期的顺序,使得第一个日期应该小于第二个日期。试试这个:[?如何计算使用PHP的两个日期之间的差异]

select post_title, post_date from wp_posts where post_date between '2016-01-01' and '2016-01-25'; 
+0

好的。有用。谢谢 –