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.
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.
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.)
AND post_date > "2011-01-01"
http://dev.mysql.com/doc/refman/5.0/en/using-date.html
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With