Page 1 of 1

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

Posted: Sat Nov 08, 2008 11:20 pm
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?

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

Posted: Sat Nov 08, 2008 11:29 pm
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.

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

Posted: Sun Nov 09, 2008 1:00 am
by oddsmojo
Try this one out:

Code: Select all

SELECT * 
FROM `myTable`
WHERE YEAR(myColumn) = 2007

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

Posted: Sun Nov 09, 2008 11:52 am
by JAB Creations
That works too! Thanks! :)