Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress SQL: Selecting posts after a certain date

Tags:

sql

wordpress

Having trouble with dates. What SQL code would I use to get all posts after 01.01.2011?

AND post_date > XXXX

Thanks in advance.

like image 235
ok1ha Avatar asked Jun 24 '11 15:06

ok1ha


People also ask

How do I select a specific date in MySQL?

You can use DATE() from MySQL to select records with a particular date. The syntax is as follows. SELECT *from yourTableName WHERE DATE(yourDateColumnName)='anyDate'; To understand the above syntax, let us first create a table.

How do I select a date from a timestamp in SQL?

In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column. (In our example, we use a column of the timestamp data type.)


2 Answers

AND post_date > "2011-01-01"

http://dev.mysql.com/doc/refman/5.0/en/using-date.html

like image 75
Dogbert Avatar answered Sep 25 '22 15:09

Dogbert


SELECT * FROM posts
WHERE post_date > '2011-01-01'
ORDER BY post_date

something like that should work, or if you want between two dates

SELECT * FROM posts
WHERE post_date BETWEEN '2011-01-01' AND '2011-02-01'
ORDER BY post_date

hope that helps

lots of good refrence here http://www.w3schools.com/sql/sql_between.asp

like image 27
loosecannon Avatar answered Sep 23 '22 15:09

loosecannon