Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im am selecting various things from a table. The problem is I only want to select them if they belong to the current year and the next year.

My table looks like this

Title Text Date

The date is formated like this 0000-00-00 and is in the format "date"

So the question is how can i select only items from only this year and the next?

Example: the year is 2012, I have items in my table that is old and i dont want them to show - I only want to select items from at the first 2012 1 January and last in this case 31 Dec 2013 current year 2012 + 1 year.

Thanks a lot for any help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
509 views
Welcome To Ask or Share your Answers For Others

1 Answer

SELECT 
  * 
FROM 
  table 
WHERE 
  YEAR(date) = YEAR(CURDATE()) 
OR 
  YEAR(date) = YEAR(CURDATE()) + 1

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...