0

How to select database rows by days ,month,years

I have table like this

id count  generatedAt
1  130    2013-01-13 02:21:02
2  120    2013-01-08 04:15:06
3  89     2013-01-08 01:42:57
4  24     2012-11-25 05:31:43
5  3      2012-02-31 09:25:24

I would like to select the rows by day or month or year.

For example by day.

2-3 is same day so I need only 1,2,4,5

for example by month,1,2,3 is same month so I need only 1,4,5

for year I need only 1,4

How can I make it?

I am using doctorine2

whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

2

You can do something like this . .
you can choose a date , month or specific year to select rows.

select * from TabeName
//for days
where DAY(myDate) = 20  
//for month
MONTH(myDate) = 12
// for year
YEAR(myDate) = 2008
AddyProg
  • 2,960
  • 13
  • 59
  • 110
  • 1
    Thanks,I understand but I need to use this in doctorine2 so I will check these articles as well.http://stackoverflow.com/questions/18826836/how-can-i-use-sqls-year-month-and-day-in-doctrine2 Thanks to you I can step forward!! – whitebear Feb 10 '14 at 07:03