MySQL SELECT * rows per year (from column NOW() insert?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

MySQL SELECT * rows per year (from column NOW() insert?

Post by JAB Creations »

In a MySQL table I have a column that when I INSERT a row I use NOW() function on the date column.

So I'm wondering (and have been wandering on MySQL's maze of a website) if there is a simple way to select all the rows that belong to the year 2007 in example?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: MySQL SELECT * rows per year (from column NOW() insert?

Post by JAB Creations »

As usual I find what I'm looking for only after I spend $x time searching. :roll:

Code: Select all

SELECT * FROM table_name WHERE column_name BETWEEN '2007-01-01 00:00:00' AND '2007-12-31 23:59:59'
I'm open to suggestions on any improvements on the query. I won't be selecting * as an afterthought.
oddsmojo
Forum Newbie
Posts: 6
Joined: Thu Nov 06, 2008 9:23 am

Re: MySQL SELECT * rows per year (from column NOW() insert?

Post by oddsmojo »

Try this one out:

Code: Select all

SELECT * 
FROM `myTable`
WHERE YEAR(myColumn) = 2007
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: MySQL SELECT * rows per year (from column NOW() insert?

Post by JAB Creations »

That works too! Thanks! :)
Post Reply